Move question most voted answer from boolean to a enumerable max by total_votes
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user