I've spent a while trying figure out the best way to authorize a controller that's from a gem with CanCan. I'm specifically using Comfortable Mexican Sofa. I have it all setup with Devise and CanCan but having trouble authorizing specific controllers from within Comfy. The closest thing I can find similar to what I'm after is in the Fortress CMS gem.
I've tried using initializers and engines to extend before_action
and write a simple auth method. The only thing I can find for CanCan and Comfy is here, but it's only addressing site login not specific controllers like pages, blogs, etc.
Basically, it comes to down - how am I able to extend a gem controller so I can authenticate a user for that controller specifically?
CanCan is an authorization library for Ruby on Rails which restricts what resources a given user is allowed to access. All permissions are defined in a single location (the Ability class) and not duplicated across controllers, views, and database queries.
CanCanCan is an authorization library for Ruby and Ruby on Rails which restricts what resources a given user is allowed to access.
On the initializer you could customize your own authorization logic:
# Uncomment this module and `config.public_authorization` above to use custom public authorization
module ComfyPublicAuthorization
def authorize
# TODO: your own authorization logic. Check params variable here
true
end
end
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With