Merge pull request #2331 from consul/current-budget-polish

Add current_budget to management controllers
This commit is contained in:
BertoCQ
2018-01-18 00:27:56 +01:00
committed by GitHub
4 changed files with 7 additions and 3 deletions

View File

@@ -5,6 +5,7 @@ class Management::BaseController < ActionController::Base
before_action :set_locale before_action :set_locale
helper_method :managed_user helper_method :managed_user
helper_method :current_user
private private
@@ -40,4 +41,7 @@ class Management::BaseController < ActionController::Base
I18n.locale = session[:locale] I18n.locale = session[:locale]
end end
def current_budget
Budget.current
end
end end

View File

@@ -19,7 +19,7 @@ class Management::BudgetsController < Management::BaseController
end end
def print_investments def print_investments
@budget = Budget.current @budget = current_budget
end end
private private

View File

@@ -5,7 +5,7 @@ class Valuation::BudgetsController < Valuation::BaseController
load_and_authorize_resource load_and_authorize_resource
def index def index
@budget = Budget.current @budget = current_budget
if @budget.present? if @budget.present?
@investments_with_valuation_open = {} @investments_with_valuation_open = {}
@investments_with_valuation_open = @budget.investments @investments_with_valuation_open = @budget.investments

View File

@@ -33,7 +33,7 @@ class Budget < ActiveRecord::Base
scope :open, -> { where.not(phase: "finished") } scope :open, -> { where.not(phase: "finished") }
def self.current def self.current
where.not(phase: "drafting").last where.not(phase: "drafting").order(:created_at).last
end end
def current_phase def current_phase