我已经安装了'acts_as_votable'宝石,并且能够成功投票。当我从文档中添加代码以便允许单个用户在单个帖子上多次投票时,它似乎不起作用。
def upvote
@video = Video.find(params[:id])
@user = User.first
@video.upvote_by @user, :duplicate => true
redirect_to :back
end
def downvote
@video = Video.find(params[:id])
@video.downvote_by User.first, :duplicate => true
redirect_to :back
end
Acts As Votable文档声明您可以将duplicate: true
发送到vote_by
,如:
@video.vote_by voter: @user, duplicate: true
现在,看一下源代码,看起来upvote_by
是vote_up
docs的别名,看着vote_up definition:
def vote_up(voter, options = {})
self.vote_by voter: voter, vote: true, vote_scope: options[:vote_scope], vote_weight: options[:vote_weight]
end
它永远不会将duplication
选项传递给vote_by
。
所以,你的解决方案是使用vote_by
代替。