Extract by_answer variable to component method

This commit is contained in:
taitus
2025-09-17 10:44:28 +02:00
parent 7f376c3005
commit 7996933fc2
2 changed files with 8 additions and 3 deletions

View File

@@ -9,7 +9,6 @@
</thead>
<tbody>
<% question.question_options.each_with_index do |option, i| %>
<% by_answer = by_question[question.id].present? ? by_question[question.id].group_by(&:answer) : {} %>
<tr id="question_<%= question.id %>_<%= i %>_result">
<td><%= option.title %></td>
<td class="text-center"><%= by_answer[option.title].present? ? by_answer[option.title].sum(&:amount) : 0 %></td>

View File

@@ -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