Commit fbf510983842852baed7bb4a1225700839ab5307
1 parent
986291ae
Exists in
master
and in
1 other branch
Change vote export to CSV to match refactored vote model
Showing
2 changed files
with
7 additions
and
7 deletions
Show diff stats
app/controllers/questions_controller.rb
... | ... | @@ -89,14 +89,14 @@ class QuestionsController < InheritedResources::Base |
89 | 89 | @question = Question.find(params[:id]) |
90 | 90 | |
91 | 91 | outfile = "question_#{@question.id}_votes" + Time.now.strftime("%m-%d-%Y") + ".csv" |
92 | - headers = ['Vote ID', 'Voter ID', 'Choice Voted on ID', 'Choice Voted on Data', 'Question ID', 'Created at', 'Updated at'] | |
92 | + headers = ['Vote ID', 'Voter ID', 'Question ID','Choice Voted on ID', 'Choice Voted on Data', 'Loser Choice ID', | |
93 | + 'Prompt ID', 'Created at', 'Updated at'] | |
94 | + @votes = @question.votes | |
93 | 95 | csv_data = FasterCSV.generate do |csv| |
94 | 96 | csv << headers |
95 | - @question.choices.each do |choice| | |
96 | - | |
97 | - choice.votes.each do |v| | |
98 | - csv << [ v.id, v.voter_id, choice.id, choice.data, @question.id, v.created_at, v.updated_at] | |
99 | - end | |
97 | + @votes.each do |v| | |
98 | + csv << [ v.id, v.voter_id, v.question_id, v.choice_id, v.choice.data, v.loser_choice_id, | |
99 | + v.prompt_id, v.created_at, v.updated_at] | |
100 | 100 | end |
101 | 101 | end |
102 | 102 | ... | ... |
app/models/visitor.rb
... | ... | @@ -30,7 +30,7 @@ class Visitor < ActiveRecord::Base |
30 | 30 | other_choices.each {|c| c.lose! } |
31 | 31 | |
32 | 32 | loser_choice = other_choices.first |
33 | - votes.create!(:question_id => prompt.question_id, :prompt_id => prompt_id, :voter_id=> self.id, :choice_id => choice.id, :loser_id => loser_choice.id) | |
33 | + votes.create!(:question_id => prompt.question_id, :prompt_id => prompt.id, :voter_id=> self.id, :choice_id => choice.id, :loser_choice_id => loser_choice.id) | |
34 | 34 | |
35 | 35 | # choice_vote = votes.create!(:voteable => choice) |
36 | 36 | # logger.info "Visitor: voted for Prompt: #{prompt.id.to_s} for choice #{choice.item.data}" | ... | ... |