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:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user