Note that we are relying on the existing `sort_by_name`[1] method in the `Budget::Heading` class. This method sorts by DESC group name first and then ASC heading name. [1] https://github.com/AyuntamientoMadrid/consul/pull/1875
30 lines
704 B
Ruby
30 lines
704 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(id: params[:budget_id])
|
|
end
|
|
|
|
def load_heading
|
|
@heading = if params[:heading_id].present?
|
|
@budget.headings.find(params[:heading_id])
|
|
else
|
|
@budget.headings.first
|
|
end
|
|
end
|
|
|
|
end
|
|
end
|