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.
32 lines
798 B
Ruby
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
|