Loads first heading if no heading_id params present
This commit is contained in:
@@ -1,22 +1,31 @@
|
|||||||
module Budgets
|
module Budgets
|
||||||
class ResultsController < ApplicationController
|
class ResultsController < ApplicationController
|
||||||
|
before_action :load_budget
|
||||||
|
before_action :load_heading
|
||||||
|
|
||||||
load_and_authorize_resource :budget
|
load_and_authorize_resource :budget
|
||||||
|
|
||||||
def show
|
def show
|
||||||
authorize! :read_results, @budget
|
authorize! :read_results, @budget
|
||||||
@investments = load_result.investments
|
@investments = load_result.investments
|
||||||
@heading = heading
|
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def load_result
|
def load_result
|
||||||
Budget::Result.new(@budget, heading)
|
Budget::Result.new(@budget, @heading)
|
||||||
end
|
end
|
||||||
|
|
||||||
def heading
|
def load_budget
|
||||||
@budget.headings.find(params[:heading_id])
|
@budget = Budget.find_by(id: params[:budget_id])
|
||||||
|
end
|
||||||
|
|
||||||
|
def load_heading
|
||||||
|
if params[:heading_id].present?
|
||||||
|
@heading = @budget.headings.find(params[:heading_id])
|
||||||
|
else
|
||||||
|
@heading = @budget.headings.first
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user