From 126941a335becac7728c67807df89f0814787602 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mar=C3=ADa=20Checa?= Date: Mon, 30 Jul 2018 18:40:24 +0200 Subject: [PATCH] Change headings reorder method --- app/controllers/budgets/executions_controller.rb | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/app/controllers/budgets/executions_controller.rb b/app/controllers/budgets/executions_controller.rb index 9db722de4..e33f43dcd 100644 --- a/app/controllers/budgets/executions_controller.rb +++ b/app/controllers/budgets/executions_controller.rb @@ -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