From 7996933fc2a4aba0a409bfc7c6a8a036c9418f78 Mon Sep 17 00:00:00 2001 From: taitus Date: Wed, 17 Sep 2025 10:44:28 +0200 Subject: [PATCH] Extract by_answer variable to component method --- .../admin/poll/results/question_component.html.erb | 1 - .../admin/poll/results/question_component.rb | 10 ++++++++-- 2 files changed, 8 insertions(+), 3 deletions(-) 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