From b79e6a01d2e3e043a93b358b7d8432628fbe09f8 Mon Sep 17 00:00:00 2001 From: Jared Cosulich Date: Fri, 3 Nov 2017 16:55:03 -0400 Subject: [PATCH] fixing most popular answer --- app/models/question.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/question.rb b/app/models/question.rb index 9688d4b8..8ffd62b9 100644 --- a/app/models/question.rb +++ b/app/models/question.rb @@ -48,7 +48,7 @@ class Question < ApplicationRecord response_answer_total = school_responses.inject(0) { |total, response| total + response.answer_index_with_reverse } histogram = school_responses.group_by(&:answer_index_with_reverse) - most_popular_answer_index = histogram.to_a.sort_by { |info| info[1].length }.last[0] + most_popular_answer_index = histogram.to_a.sort_by { |info| info[1].length }.last[0] + 1 most_popular_answer = options_with_reverse[most_popular_answer_index - 1] AggregatedResponses.new(