0

使用can后无法查看评论中的编辑或删除,评论与工作相关。

user ||= User.new # guest user (not logged in)
        if user.admin?
            can :access, :rails_admin       # only allow admin users to access Rails Admin
            can :dashboard
            can :manage, :all
        else
            can :read, :all
            can [ :edit, :update, :destroy ], Comment do |comment|
                comment.try(:user_id) == user.id
            end

            can [ :edit, :update, :destroy ], Job do |job|
                job.user_id == user.id
            end
        can :create , Comment
        can :create , Job
        end

- if can? :update, @comment
	= link_to "Edit", edit_job_comment_path(comment.job, comment)

- if can? :destroy, @comment
	= link_to "Delete", [comment.job, comment], method: :delete, data: { confirm: "Are you sure?" }

4

1 回答 1

-1

尝试以下代码:

can [ :edit, :update, :destroy ], Comment, :user_id => user.id
can [ :edit, :update, :destroy ], Job, :user_id => user.id 
于 2015-05-24T09:42:36.617 回答