Ruby on rails Rails:向上投票的用户列表

Ruby on rails Rails:向上投票的用户列表,ruby-on-rails,ruby,ruby-on-rails-4,Ruby On Rails,Ruby,Ruby On Rails 4,在我的rails应用程序中,我有一个向上投票系统,它允许人们向上投票。然后,当用户向上投票时,我在用户配置文件中呈现向上投票的管脚列表。我想知道的是提供一个向上投票的用户列表 app/controller/pins_controller.rb def upvote @pin = Pin.find(params[:id]) if @pin.votes.create(user_id: current_user.id) flash[:notice] = "Thank you for

在我的rails应用程序中,我有一个向上投票系统,它允许人们向上投票。然后,当用户向上投票时,我在用户配置文件中呈现向上投票的管脚列表。我想知道的是提供一个向上投票的用户列表

app/controller/pins_controller.rb

def upvote
  @pin = Pin.find(params[:id])

  if @pin.votes.create(user_id: current_user.id)
    flash[:notice] =  "Thank you for upvoting! You can upvote a startup only once."
    redirect_to(pins_path)
  else 
    flash[:notice] =  "You have already upvoted this!"
    redirect_to(pins_path)
  end
end
def show
    @user = User.find(params[:id])
    @pins_for_user = [] 
    @user.votes.each do |vote| 
    @pins_for_user << vote.pin    
    end
end
app/controller/users\u controller.rb

def upvote
  @pin = Pin.find(params[:id])

  if @pin.votes.create(user_id: current_user.id)
    flash[:notice] =  "Thank you for upvoting! You can upvote a startup only once."
    redirect_to(pins_path)
  else 
    flash[:notice] =  "You have already upvoted this!"
    redirect_to(pins_path)
  end
end
def show
    @user = User.find(params[:id])
    @pins_for_user = [] 
    @user.votes.each do |vote| 
    @pins_for_user << vote.pin    
    end
end
app/models/pin.rb

class Pin < ActiveRecord::Base

    belongs_to :user

    has_many :votes, dependent: :destroy
    has_many :upvoted_users, through: :votes, source: :user

    has_many :rewards, dependent: :destroy
    has_many :rewarded_users, through: :rewards, source: :user

    has_attached_file :image, :styles => { :medium => "300x300>", :thumb => "100x100>" }
    has_attached_file :logo, :styles => { :medium => "300x300>", :thumb => "100x100>" }

    end
app/models/user.rb

class User < ActiveRecord::Base
  # Include default devise modules. Others available are:
  # :confirmable, :lockable, :timeoutable and :omniauthable
  devise :database_authenticatable, :registerable,
         :recoverable, :rememberable, :trackable, :validatable

  has_many :pins    
  has_many :votes, dependent: :destroy
  has_many :upvoted_pins, through: :votes, source: :pin

  has_many :rewards, dependent: :destroy
  has_many :rewarded_pins, through: :rewards, source: :pin

end
app/models/vote.rb

class Vote < ActiveRecord::Base

belongs_to :user
belongs_to :pin, counter_cache: true
validates_uniqueness_of :pin_id, scope: :user_id

end

我曾考虑使用@pin.upvoted_用户提供此列表,但我没有成功地将其正确实施,有什么想法吗?

您能详细说明您面对upvoted_用户时遇到的问题吗。你也检查了gem'acts_as_votable'-你有什么错误?显示你的投票模型类。我用投票模型编辑了我的问题!@pin.upu用户返回什么?