[英]How to allow a single User to vote multiple times on a single Post with the 'acts_as_votable' gem
I've installed the 'acts_as_votable' gem, and am able to vote successfully. 我已经安装了“ acts_as_votable” gem,并且能够成功投票。 When I add the code from the documentation to be able to allow a single User to vote multiple times on a single Post it doesn't seem to work. 当我从文档中添加代码以允许单个用户对单个帖子多次投票时,它似乎不起作用。
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 documentation states that you can send duplicate: true
to vote_by
like: 充当Votable文档指出,您可以发送duplicate: true
的vote_by
例如:
@video.vote_by voter: @user, duplicate: true
Now, looking at the source code, it seems like upvote_by
is an alias for vote_up
docs , and looking at vote_up definition : 现在,看一下源代码,似乎upvote_by
是vote_up
docs的别名,然后看一下vote_up定义 :
def vote_up(voter, options = {})
self.vote_by voter: voter, vote: true, vote_scope: options[:vote_scope], vote_weight: options[:vote_weight]
end
it never passes duplication
option to vote_by
. 它永远不会将duplication
选项传递给vote_by
。
So, your solution would be to use vote_by
instead. 因此,您的解决方案将改为使用vote_by
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.