Simplify managing investment votes

If I'm right, the `investment_votes` instance variable only exists to
avoid several database queries to get whether the current user has
supported each of the investments.

However, that doesn't make much sense when only one investment is shown.
In this case, the number of queries stays the same, and so we can
simplify the code by rendering the component with an optional parameter.
This commit is contained in:
Javi Martín
2021-06-13 02:55:09 +02:00
parent d5f4313f59
commit 5fab843184
11 changed files with 16 additions and 28 deletions

View File

@@ -60,7 +60,6 @@ module Budgets
@comment_tree = CommentTree.new(@commentable, params[:page], @current_order)
@related_contents = Kaminari.paginate_array(@investment.relationed_contents).page(params[:page]).per(5)
set_comment_flags(@comment_tree.comments)
load_investment_votes(@investment)
@investment_ids = [@investment.id]
@remote_translations = detect_remote_translations([@investment], @comment_tree.comments)
end
@@ -94,7 +93,6 @@ module Budgets
def vote
@investment.register_selection(current_user)
load_investment_votes(@investment)
respond_to do |format|
format.html { redirect_to budget_investments_path(heading_id: @investment.heading.id) }
format.js