Extract BudgetHeadingsHelper#heading_link & use it

Why:

The logic to construct the link to a heading (if it exists) is in three
different places, this is a clear candidate for a helper method.

How:

Just checking at the helper method if `assigned_heading` and `budget`
has values and composing the link if so.
This commit is contained in:
decabeza
2018-03-05 19:01:11 +01:00
parent 0e9190bc43
commit d70c46e578
4 changed files with 9 additions and 14 deletions

View File

@@ -6,4 +6,10 @@ module BudgetHeadingsHelper
end
end
def heading_link(assigned_heading = nil, budget = nil)
return nil unless assigned_heading && budget
heading_path = budget_investments_path(budget, heading_id: assigned_heading.try(:id))
link_to(assigned_heading.name, heading_path)
end
end

View File

@@ -53,19 +53,13 @@
<% change_ballot = link_to(t("budgets.ballots.reasons_for_not_balloting.change_ballot"),
budget_ballot_path(@budget))%>
<% if @assigned_heading.present? %>
<% heading_link = link_to(@assigned_heading.name,
budget_investments_path(@budget,
heading_id: @assigned_heading.try(:id))) %>
<% end %>
<p>
<small>
<%= t("budgets.ballots.reasons_for_not_balloting.#{reason}",
verify_account: verify_account, signin: signin,
signup: signup, my_heading: my_heading,
change_ballot: change_ballot,
heading_link: heading_link).html_safe %>
heading_link: heading_link(@assigned_heading, @budget)).html_safe %>
</small>
</p>
</div>

View File

@@ -37,10 +37,7 @@
<div class="small-12 medium-9">
<div class="callout warning margin-top">
<%= t("budgets.investments.header.different_heading_assigned_html",
heading_link: link_to(
@assigned_heading.name,
budget_investments_path(@budget, heading_id: @assigned_heading.try(:id)))
) %>
heading_link: heading_link(@assigned_heading, @budget)) %>
<br>
<small>
<%= t("budgets.investments.header.change_ballot",

View File

@@ -43,9 +43,7 @@
<% elsif @assigned_heading.present? %>
<p>
<%= t("budgets.investments.index.sidebar.different_heading_assigned_html",
heading_link: link_to(
@assigned_heading.name,
budget_investments_path(@budget, heading_id: @assigned_heading.try(:id)))
heading_link: heading_link(@assigned_heading, @budget)
) %>
<br>
<small>