Adds more controller variables and uses them in investment controller

This commit is contained in:
kikito
2016-12-05 17:35:40 +01:00
parent 407ad301d1
commit 882565aeca
2 changed files with 17 additions and 1 deletions

View File

@@ -6,6 +6,8 @@ class Management::Budgets::InvestmentsController < Management::BaseController
def index def index
@investments = apply_filters_and_search(Budget::Investment).order(cached_votes_up: :desc).page(params[:page]).for_render @investments = apply_filters_and_search(Budget::Investment).order(cached_votes_up: :desc).page(params[:page]).for_render
@investment_ids = @investments.pluck(:id)
set_investment_ballots(@investments)
set_budget_investment_votes(@investments) set_budget_investment_votes(@investments)
end end
@@ -26,11 +28,13 @@ class Management::Budgets::InvestmentsController < Management::BaseController
end end
def show def show
set_investment_ballots(@investment)
set_budget_investment_votes(@investment) set_budget_investment_votes(@investment)
end end
def vote def vote
@investment.register_vote(managed_user, 'yes') @investment.register_vote(managed_user, 'yes')
set_investment_ballots(@investment)
set_budget_investment_votes(@investment) set_budget_investment_votes(@investment)
end end
@@ -42,6 +46,13 @@ class Management::Budgets::InvestmentsController < Management::BaseController
private private
def set_investment_ballots(investments)
@investment_ballots = {}
Budget.where(id: Array.wrap(investments).map(&:budget_id).uniq).each do |budget|
@investment_ballots[budget] = Budget::Ballot.where(user: current_user, budget: budget).first_or_create
end
end
def set_budget_investment def set_budget_investment
@investment = Budget::Investment.find(params[:id]) @investment = Budget::Investment.find(params[:id])
end end

View File

@@ -18,7 +18,12 @@
</div> </div>
<% @investments.each do |investment| %> <% @investments.each do |investment| %>
<%= render partial: '/budgets/investments/investment', locals: { investment: investment, investment_votes: @investment_votes } %> <%= render partial: '/budgets/investments/investment', locals: {
investment: investment,
investment_ids: @investment_ids,
investment_votes: @investment_votes,
investment_ballots: @investment_ballots
} %>
<% end %> <% end %>
<%= paginate @investments %> <%= paginate @investments %>