Load budget headings on budgets/executions#show action

This commit is contained in:
Angel Perez
2018-07-02 22:22:07 -04:00
committed by Javi Martín
parent 0a95abc30d
commit 5de74ea6f1
2 changed files with 2 additions and 21 deletions

View File

@@ -1,14 +1,13 @@
module Budgets
class ExecutionsController < ApplicationController
before_action :load_budget
before_action :load_heading
before_action :load_investments
load_and_authorize_resource :budget
def show
authorize! :read_executions, @budget
@statuses = ::Budget::Investment::Status.all
@headings = @budget.headings.order(id: :asc)
end
private
@@ -17,23 +16,5 @@ module Budgets
@budget = Budget.find_by(slug: params[:id]) || Budget.find_by(id: params[:id])
end
def load_heading
@heading = if params[:heading_id].present?
@budget.headings.find_by(slug: params[:heading_id])
else
@heading = @budget.headings.first
end
end
def load_investments
@investments = Budget::Result.new(@budget, @heading).investments.joins(:milestones)
if params[:status].present?
@investments.where('budget_investment_milestones.status_id = ?', params[:status])
else
@investments
end
end
end
end

View File

@@ -44,7 +44,7 @@
<%= t("budgets.executions.heading_selection_title") %>
</h3>
<ul class="menu vertical no-margin-top no-padding-top">
<% @budget.headings.order('id ASC').each do |heading| %>
<% @headings.each do |heading| %>
<li>
<%= link_to heading.name, "#" %>
</li>