Change headings reorder method

This commit is contained in:
María Checa
2018-07-30 18:40:24 +02:00
committed by Javi Martín
parent 810bdae37a
commit 126941a335

View File

@@ -22,7 +22,7 @@ module Budgets
.distinct.group_by(&:heading)
end
@headings = reorder_alphabetically_with_city_heading_first(@headings)
@investments_by_heading = reorder_alphabetically_with_city_heading_first.to_h
end
private
@@ -30,5 +30,17 @@ module Budgets
def load_budget
@budget = Budget.find_by(slug: params[:id]) || Budget.find_by(id: params[:id])
end
def reorder_alphabetically_with_city_heading_first
@investments_by_heading.sort do |a, b|
if a[0].name == 'Toda la ciudad'
-1
elsif b[0].name == 'Toda la ciudad'
1
else
a[0].name <=> b[0].name
end
end
end
end
end