From eca971a648e5efd8a69ff39ade7010cb74d3903f Mon Sep 17 00:00:00 2001 From: rgarcia Date: Tue, 16 Jan 2018 19:34:21 +0100 Subject: [PATCH 1/3] Use `current_budget` instead of `Budget.current` --- app/controllers/management/budgets_controller.rb | 2 +- app/controllers/valuation/budgets_controller.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/controllers/management/budgets_controller.rb b/app/controllers/management/budgets_controller.rb index 470d1f9fd..b83d843e2 100644 --- a/app/controllers/management/budgets_controller.rb +++ b/app/controllers/management/budgets_controller.rb @@ -19,7 +19,7 @@ class Management::BudgetsController < Management::BaseController end def print_investments - @budget = Budget.current + @budget = current_budget end private diff --git a/app/controllers/valuation/budgets_controller.rb b/app/controllers/valuation/budgets_controller.rb index cf99f95e3..9789ab929 100644 --- a/app/controllers/valuation/budgets_controller.rb +++ b/app/controllers/valuation/budgets_controller.rb @@ -5,7 +5,7 @@ class Valuation::BudgetsController < Valuation::BaseController load_and_authorize_resource def index - @budget = Budget.current + @budget = current_budget if @budget.present? @investments_with_valuation_open = {} @investments_with_valuation_open = @budget.investments From 21cdddcbae55e25be4049ad25c590acb5bed71cc Mon Sep 17 00:00:00 2001 From: rgarcia Date: Tue, 16 Jan 2018 19:44:11 +0100 Subject: [PATCH 2/3] Order budgets by `created_at` instead of by `id` This is a preventive change which will be useful once the rake to migrate from `spending_proposals` to `budget_investments` is complete As after running that migration, old `spending_proposal` budgets will have a newer `id` than the existing budgets. And therefore the last budget will be one of those migrated from the old `spending_proposal` model By ordering by `created_at` and probably updating the `created_at` attribute in the rake that migrates `spending_proposals` to `budget_investments`, we will have a coherent order for budgets --- app/models/budget.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/budget.rb b/app/models/budget.rb index 608599217..418e9aac0 100644 --- a/app/models/budget.rb +++ b/app/models/budget.rb @@ -33,7 +33,7 @@ class Budget < ActiveRecord::Base scope :open, -> { where.not(phase: "finished") } def self.current - where.not(phase: "drafting").last + where.not(phase: "drafting").order(:created_at).last end def description From 952df2947a9df01e35f34636a5eed3dcbb0919ec Mon Sep 17 00:00:00 2001 From: rgarcia Date: Wed, 17 Jan 2018 12:50:17 +0100 Subject: [PATCH 3/3] Duplicate current_budget method in management_base_controller This method is already existent in the application_controller but it seems a little overkill to create a concern just for this method Maybe when we have multiple method it makes sense to create a nice controller. Another option would be to make the management_base_controller extend from the application_controller --- app/controllers/management/base_controller.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/app/controllers/management/base_controller.rb b/app/controllers/management/base_controller.rb index 66aee5a01..c7610eba9 100644 --- a/app/controllers/management/base_controller.rb +++ b/app/controllers/management/base_controller.rb @@ -5,6 +5,7 @@ class Management::BaseController < ActionController::Base before_action :set_locale helper_method :managed_user + helper_method :current_user private @@ -40,4 +41,7 @@ class Management::BaseController < ActionController::Base I18n.locale = session[:locale] end + def current_budget + Budget.current + end end