diff --git a/app/components/budgets/investments/votes_component.rb b/app/components/budgets/investments/votes_component.rb index 7fb20dba3..1350f5be6 100644 --- a/app/components/budgets/investments/votes_component.rb +++ b/app/components/budgets/investments/votes_component.rb @@ -3,7 +3,7 @@ class Budgets::Investments::VotesComponent < ApplicationComponent delegate :namespace, :current_user, :voted_for?, :image_absolute_url, :link_to_verify_account, :link_to_signin, :link_to_signup, to: :helpers - def initialize(investment, investment_votes:) + def initialize(investment, investment_votes: nil) @investment = investment @investment_votes = investment_votes end @@ -28,7 +28,11 @@ class Budgets::Investments::VotesComponent < ApplicationComponent end def user_voted_for? - @user_voted_for ||= voted_for?(investment_votes, investment) + @user_voted_for ||= if investment_votes + voted_for?(investment_votes, investment) + else + current_user&.voted_for?(investment) + end end def display_support_alert? diff --git a/app/controllers/budgets/investments_controller.rb b/app/controllers/budgets/investments_controller.rb index e681160bc..4f25c78a5 100644 --- a/app/controllers/budgets/investments_controller.rb +++ b/app/controllers/budgets/investments_controller.rb @@ -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 diff --git a/app/controllers/management/budgets/investments_controller.rb b/app/controllers/management/budgets/investments_controller.rb index 3a642e173..2cecdb6c3 100644 --- a/app/controllers/management/budgets/investments_controller.rb +++ b/app/controllers/management/budgets/investments_controller.rb @@ -37,12 +37,10 @@ class Management::Budgets::InvestmentsController < Management::BaseController end def show - load_investment_votes(@investment) end def vote @investment.register_selection(managed_user) - load_investment_votes(@investment) respond_to do |format| format.html { redirect_to management_budget_investments_path(heading_id: @investment.heading.id) } format.js diff --git a/app/views/budgets/investments/_investment.html.erb b/app/views/budgets/investments/_investment.html.erb index 4d3b68acc..79b6d8cf2 100644 --- a/app/views/budgets/investments/_investment.html.erb +++ b/app/views/budgets/investments/_investment.html.erb @@ -38,9 +38,8 @@