Files
nairobi/app/controllers/budgets/results_controller.rb
Javi Martín 70a07c095f Add and apply Style/BlockDelimiters rubocop rule
We were already using it most of the time, but there were a few places
were we used brackets for multiline blocks.
2019-10-05 14:44:14 +02:00

40 lines
1.0 KiB
Ruby

module Budgets
class ResultsController < ApplicationController
before_action :load_budget
before_action :load_heading
include DownloadSettingsHelper
load_and_authorize_resource :budget
def show
authorize! :read_results, @budget
@investments = Budget::Result.new(@budget, @heading).investments
@headings = @budget.headings.sort_by_name
respond_to do |format|
format.html
format.csv do
send_data to_csv(@investments.compatible, Budget::Investment),
type: "text/csv",
disposition: "attachment",
filename: "budget_investment_results.csv"
end
end
end
private
def load_budget
@budget = Budget.find_by_slug_or_id(params[:budget_id]) || Budget.first
end
def load_heading
if @budget.present?
headings = @budget.headings
@heading = headings.find_by_slug_or_id(params[:heading_id]) || headings.first
end
end
end
end