Files
nairobi/app/controllers/budgets/results_controller.rb
Julian Herrero 4bd20eebf4 Use correct param in controller
There were some custom routes created using the param[:id] but the
Rails routes use the param[:budget_id] by default, so the same
controller could be asked for different param keys.
2019-06-03 16:54:39 +02:00

32 lines
798 B
Ruby

module Budgets
class ResultsController < ApplicationController
before_action :load_budget
before_action :load_heading
load_and_authorize_resource :budget
def show
authorize! :read_results, @budget
@investments = Budget::Result.new(@budget, @heading).investments
@headings = @budget.headings.sort_by_name
end
private
def load_budget
@budget = Budget.find_by(slug: params[:budget_id])
@budget ||= Budget.find_by(id: params[:budget_id])
@budget ||= Budget.first
end
def load_heading
@heading = if params[:heading_id].present?
@budget.headings.find(params[:heading_id])
else
@budget.headings.first
end
end
end
end