我可以投票,但它不会让新用户投票同样的事情?用户可以投票没有投票的东西,一旦他们投票,其他用户就不会让他们投票。
我已经设置了CanCan,我注意到它给了我同样的错误,好像我无法访问某些东西。所以,我假设它与某些身份验证有关?不让其他用户投票?我的:upvote
中有:unvote
和before_action
是错误的吗?
控制器
class ProjectsController < ApplicationController
load_and_authorize_resource
before_action :set_project, only: [:show, :edit, :update, :destroy, :upvote, :unvote]
before_action :authenticate_user!, only: [:edit, :update, :new, :upvote, :unvote]
def upvote
@project.liked_by current_user
redirect_to :back
end
def unvote
@project.unliked_by current_user
redirect_to :back
end
... #more codes here...
end
查看
- unless (current_user.voted_for? @project) && (@project.liked_by current_user)
= link_to like_project_path(@project), method: :put, class: "btn btn-default" do
%span.glyphicon.glyphicon-heart
= @project.get_likes.size
- else
= link_to unvote_project_path(@project), method: :put, class: "btn btn-default" do
%span.glyphicon.glyphicon-heart
= @project.get_likes.size