Files
nairobi/app/helpers/budget_headings_helper.rb
decabeza d70c46e578 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.
2018-03-08 11:50:23 +01:00

16 lines
450 B
Ruby

module BudgetHeadingsHelper
def budget_heading_select_options(budget)
budget.headings.order_by_group_name.map do |heading|
[heading.name_scoped_by_group, heading.id]
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