Files
grecia/app/controllers/budgets/executions_controller.rb
Senén Rodero Rodríguez 596ef8d1ed Fix queries and scopes after column deletion
Some queries were accessing original column instead of the new
translatable one. This should have been causing unexpected behavior
for requests maded in a different locale than the application default.
2019-04-17 17:40:55 +02:00

36 lines
989 B
Ruby

module Budgets
class ExecutionsController < ApplicationController
before_action :load_budget
load_and_authorize_resource :budget
def show
authorize! :read_executions, @budget
@statuses = Milestone::Status.all
@investments_by_heading = investments_by_heading_ordered_alphabetically.to_h
end
private
def investments_by_heading
if params[:status].present?
@budget.investments.winners
.with_milestone_status_id(params[:status])
.uniq
.group_by(&:heading)
else
@budget.investments.winners
.joins(milestones: :translations)
.distinct.group_by(&:heading)
end
end
def load_budget
@budget = Budget.find_by_slug_or_id params[:budget_id]
end
def investments_by_heading_ordered_alphabetically
investments_by_heading.sort { |a, b| a[0].name <=> b[0].name }
end
end
end