How to use CanCan with gem controllers?
Asked Answered
C

1

10

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?

Circosta answered 4/11, 2015 at 18:50 Comment(0)
B
5

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
Bonanza answered 8/11, 2015 at 15:32 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.