We were very inconsistent regarding these rules. Personally I prefer no empty lines around blocks, clases, etc... as recommended by the Ruby style guide [1], and they're the default values in rubocop, so those are the settings I'm applying. The exception is the `private` access modifier, since we were leaving empty lines around it most of the time. That's the default rubocop rule as well. Personally I don't have a strong preference about this one. [1] https://rubystyle.guide/#empty-lines-around-bodies
39 lines
1.0 KiB
Ruby
39 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
|