开发者

Rails thumbs_up error Validation failed: Voteable has already been taken

开发者 https://www.devze.com 2023-04-06 17:09 出处:网络
So thumbs_up does exactly what I want it to, but when I try to double vote I get this error Validation failed: Voteable has already been taken instead of being redirected to the previous page and Im开

So thumbs_up does exactly what I want it to, but when I try to double vote I get this error Validation failed: Voteable has already been taken instead of being redirected to the previous page and Im开发者_开发知识库 not sure how to do that


OK, I dont know if its supposed to redirect automatically like Vote_fu does but I fixed it by adding an if/else in the controller to see if the current user has voted on the item or not.

unless current_member.voted_for?(@tattoo)
  current_member.vote_for(@tattoo)
  redirect_to :back
else
  redirect_to :back
end
0

精彩评论

暂无评论...
验证码 换一张
取 消