我目前有一个评论控制器,它有方法 vote_up 和 vote_down 这就是我的 vote_up 当前的工作方式。
我的评论模型有描述和计数字段。
def vote_up
@comment = Comment.find(params[:comment_id])
@comment.count += 1
if @comment.save
flash[:notice] = "Thank you for voting"
respond_to do |format|
format.html { redirect_to show_question_path(@comment.question) }
format.js
end
else
flash[:notice] = "Error Voting Please Try Again"
redirect_to show_question_path(@comment.question)
end
end
这允许上下多次投票。我将如何设计它,以便用户每条评论只能投票一次,但以某种方式跟踪他们是否投了赞成票或反对票,因此他们也可以根据需要更改投票。