Move question most voted answer from boolean to a enumerable max by total_votes

This commit is contained in:
Bertocq
2017-10-24 14:57:37 +02:00
committed by Javi Martín
parent 84eac6ff68
commit b8dbdaf9a7
4 changed files with 7 additions and 18 deletions

View File

@@ -62,4 +62,7 @@ class Poll::Question < ApplicationRecord
question_answers.inject(0) { |total, question_answer| total + question_answer.total_votes }
end
def most_voted_answer_id
question_answers.max_by { |answer| answer.total_votes }.id
end
end