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 has_filters %w{valuation_open without_admin managed valuating valuation_finished all}, only: :index
def 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 end
def show def show
@@ -21,7 +23,7 @@ class Admin::BudgetInvestmentsController < Admin::BaseController
load_tags load_tags
end end
def update def update
if @investment.update(budget_investment_params) if @investment.update(budget_investment_params)
redirect_to admin_budget_budget_investment_path(@budget, @investment, Budget::Investment.filter_params(params)), redirect_to admin_budget_budget_investment_path(@budget, @investment, Budget::Investment.filter_params(params)),
notice: t("flash.actions.update.budget_investment") notice: t("flash.actions.update.budget_investment")
@@ -36,7 +38,8 @@ class Admin::BudgetInvestmentsController < Admin::BaseController
private private
def budget_investment_params 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 end
def load_budget def load_budget
@@ -60,8 +63,7 @@ class Admin::BudgetInvestmentsController < Admin::BaseController
end end
def load_ballot def load_ballot
if @budget.balloting? query = Budget::Ballot.where(user: current_user, budget: @budget)
@ballot = Budget::Ballot.where(user: current_user, budget: @budget).first_or_create @ballot = @budget.balloting? ? query.first_or_create : query.first_or_initialize
end
end end
end end