Mateusz Urbański
Mateusz Urbański

Reputation: 7862

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?

Upvotes: 5

Views: 5513

Answers (2)

stevec
stevec

Reputation: 52208

For me, using cancancan, it was as simple as replacing this

load_and_authorize_resource

with this

load_and_authorize_resource except: :webhook

and then the /webhook url worked without authorization

Upvotes: 0

strivedi183
strivedi183

Reputation: 4831

I think something like this might work in your controller,

skip_authorization_check only: :confirm
load_and_authorize_resource except: :confirm

Hope this helps!

Upvotes: 10

Related Questions