Commit fbf510983842852baed7bb4a1225700839ab5307

Authored by Dhruv Kapadia
1 parent 986291ae

Change vote export to CSV to match refactored vote model

app/controllers/questions_controller.rb
@@ -89,14 +89,14 @@ class QuestionsController < InheritedResources::Base @@ -89,14 +89,14 @@ class QuestionsController < InheritedResources::Base
89 @question = Question.find(params[:id]) 89 @question = Question.find(params[:id])
90 90
91 outfile = "question_#{@question.id}_votes" + Time.now.strftime("%m-%d-%Y") + ".csv" 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 csv_data = FasterCSV.generate do |csv| 95 csv_data = FasterCSV.generate do |csv|
94 csv << headers 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 end 100 end
101 end 101 end
102 102
app/models/visitor.rb
@@ -30,7 +30,7 @@ class Visitor &lt; ActiveRecord::Base @@ -30,7 +30,7 @@ class Visitor &lt; ActiveRecord::Base
30 other_choices.each {|c| c.lose! } 30 other_choices.each {|c| c.lose! }
31 31
32 loser_choice = other_choices.first 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 # choice_vote = votes.create!(:voteable => choice) 35 # choice_vote = votes.create!(:voteable => choice)
36 # logger.info "Visitor: voted for Prompt: #{prompt.id.to_s} for choice #{choice.item.data}" 36 # logger.info "Visitor: voted for Prompt: #{prompt.id.to_s} for choice #{choice.item.data}"