only creates ballots when budget balloting

This commit is contained in:
kikito
2016-12-25 12:54:07 +01:00
parent 2fab251593
commit 3fd1993f74

View File

@@ -9,7 +9,9 @@ class Admin::BudgetInvestmentsController < Admin::BaseController
has_filters %w{valuation_open without_admin managed valuating valuation_finished all}, only: :index
def index
@investments = Budget::Investment.scoped_filter(params, @current_filter).order(cached_votes_up: :desc, created_at: :desc).page(params[:page])
@investments = Budget::Investment.scoped_filter(params, @current_filter)
.order(cached_votes_up: :desc, created_at: :desc)
.page(params[:page])
end
def show
@@ -36,7 +38,8 @@ class Admin::BudgetInvestmentsController < Admin::BaseController
private
def budget_investment_params
params.require(:budget_investment).permit(:title, :description, :external_url, :heading_id, :administrator_id, :tag_list, valuator_ids: [])
params.require(:budget_investment)
.permit(:title, :description, :external_url, :heading_id, :administrator_id, :tag_list, valuator_ids: [])
end
def load_budget
@@ -60,8 +63,7 @@ class Admin::BudgetInvestmentsController < Admin::BaseController
end
def load_ballot
if @budget.balloting?
@ballot = Budget::Ballot.where(user: current_user, budget: @budget).first_or_create
end
query = Budget::Ballot.where(user: current_user, budget: @budget)
@ballot = @budget.balloting? ? query.first_or_create : query.first_or_initialize
end
end