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
25 lines
503 B
Ruby
25 lines
503 B
Ruby
module Budgets
|
|
class StatsController < ApplicationController
|
|
|
|
before_action :load_budget
|
|
load_and_authorize_resource :budget
|
|
|
|
def show
|
|
authorize! :read_stats, @budget
|
|
@stats = load_stats
|
|
@headings = @budget.headings.sort_by_name
|
|
end
|
|
|
|
private
|
|
|
|
def load_stats
|
|
Budget::Stats.new(@budget).generate
|
|
end
|
|
|
|
def load_budget
|
|
@budget = Budget.find_by(slug: params[:budget_id]) || Budget.find_by(id: params[:budget_id])
|
|
end
|
|
|
|
end
|
|
end
|