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