Extract by_answer variable to component method
This commit is contained in:
@@ -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>
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user