It will make it far easier to call other methods on the stats object, and we're already caching the methods. We had to remove the view fragment caching because the stats object isn't as easy to cache. The good thing about it is the view will automatically be updated when we change logic regarding which stats to show, and the methods taking long to execute are cached in the model.
21 lines
443 B
Ruby
21 lines
443 B
Ruby
module Budgets
|
|
class StatsController < ApplicationController
|
|
|
|
before_action :load_budget
|
|
load_and_authorize_resource :budget
|
|
|
|
def show
|
|
authorize! :read_stats, @budget
|
|
@stats = Budget::Stats.new(@budget)
|
|
@headings = @budget.headings.sort_by_name
|
|
end
|
|
|
|
private
|
|
|
|
def load_budget
|
|
@budget = Budget.find_by(slug: params[:budget_id]) || Budget.find_by(id: params[:budget_id])
|
|
end
|
|
|
|
end
|
|
end
|