Extract methods in ballot component

Assigning variables in the view makes the code harder to read.
This commit is contained in:
Javi Martín
2021-09-16 12:24:55 +02:00
parent 4243de3062
commit 9f94e95689
2 changed files with 10 additions and 2 deletions

View File

@@ -15,7 +15,6 @@
</header> </header>
<div class="row ballot"> <div class="row ballot">
<% ballot_groups = ballot.groups.sort_by_name %>
<% ballot_groups.each do |group| %> <% ballot_groups.each do |group| %>
<% heading = ballot.heading_for_group(group) %> <% heading = ballot.heading_for_group(group) %>
<div id="<%= dom_id(group) %>" class="small-12 medium-6 column end"> <div id="<%= dom_id(group) %>" class="small-12 medium-6 column end">
@@ -46,7 +45,6 @@
</div> </div>
<% end %> <% end %>
<% no_balloted_groups = budget.groups.sort_by_name - ballot_groups %>
<% no_balloted_groups.each do |group| %> <% no_balloted_groups.each do |group| %>
<div id="<%= dom_id(group) %>" class="small-12 medium-6 column end"> <div id="<%= dom_id(group) %>" class="small-12 medium-6 column end">
<div class="margin-top ballot-content"> <div class="margin-top ballot-content">

View File

@@ -8,4 +8,14 @@ class Budgets::Ballot::BallotComponent < ApplicationComponent
def budget def budget
ballot.budget ballot.budget
end end
private
def ballot_groups
ballot.groups.sort_by_name
end
def no_balloted_groups
budget.groups.sort_by_name - ballot.groups
end
end end