diff --git a/app/components/admin/poll/results/question_component.html.erb b/app/components/admin/poll/results/question_component.html.erb index 9cf0cd4d1..aac83af2f 100644 --- a/app/components/admin/poll/results/question_component.html.erb +++ b/app/components/admin/poll/results/question_component.html.erb @@ -9,7 +9,6 @@ <% question.question_options.each_with_index do |option, i| %> - <% by_answer = by_question[question.id].present? ? by_question[question.id].group_by(&:answer) : {} %> <%= option.title %> <%= by_answer[option.title].present? ? by_answer[option.title].sum(&:amount) : 0 %> diff --git a/app/components/admin/poll/results/question_component.rb b/app/components/admin/poll/results/question_component.rb index 2bee2a328..2b14743ce 100644 --- a/app/components/admin/poll/results/question_component.rb +++ b/app/components/admin/poll/results/question_component.rb @@ -6,7 +6,13 @@ class Admin::Poll::Results::QuestionComponent < ApplicationComponent @partial_results = partial_results end - def by_question - @by_question ||= partial_results.group_by(&:question_id) + def by_answer + @by_answer ||= by_question[question.id].present? ? by_question[question.id].group_by(&:answer) : {} end + + private + + def by_question + @by_question ||= partial_results.group_by(&:question_id) + end end