ruby-on-railsrubyruby-on-rails-4cancan

CanCan skip authorization for some action


I have problem with CanCan gem which I can't solve. In my controller I have action "confirm" which is a member route for "reservations" resource. I don't want to authorize resource by CanCan in this action so I do something like that in controller:

load_and_authorize_resource except: :confirm

But now I have error:

This action failed the check_authorization because it does not authorize_resource. Add skip_authorization_check to bypass this check.

How can I skip authorization for proper action in CanCan?


Solution

  • I think something like this might work in your controller,

    skip_authorization_check only: :confirm
    load_and_authorize_resource except: :confirm
    

    Hope this helps!