使用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?" }