0

After using cancan not able to view edit or delete in the comments,comments are related to jobs.

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?" }
Nike
  • 61
  • 9

1 Answers1

-1

try the following code :

can [ :edit, :update, :destroy ], Comment, :user_id => user.id
can [ :edit, :update, :destroy ], Job, :user_id => user.id 
Maroo-b
  • 187
  • 7