I'm having some trouble getting ActiveAdmin to work with CanCanCan. I'm using CanCanCan version 1.9.2 and ActiveAdmin version 1.0.0.pre in a Rails 4 app. After setting up my ability class and enabling authorization checks in the rest of my app by adding load_and_authorize_resource
and check_authorization
to my ApplicationController, I get the error
protected method 'authorize!' called for #<Activeadmin::<SomeControler>> (NoMethodError)
After some searching, I ran into this this GitHub issue that looks exactly like the problem I'm having. The solution does not work at all for me, however. In config/initializers/active_admin.rb I have, among other things:
...
config.authorization_adapter = ActiveAdmin::CanCanAdapter
...
I have also ensured that I have no references to controller.authorize_resource
in any ActiveAdmin controller, yet I still get the protected method authorize! ...
error when I try to access any ActiveAdmin resources from my integration tests.
After some more trial and error and more searching, I discovered that calling load_and_authorize_resource
from ApplicationController was not recommended, and that setting ActiveAdmin's authorization_adapter to CanCanAdapter as I did above should automatically enable CanCanCan's authorization checks in ActiveAdmin, but check_authorization
fails because the resource was not authorized for every ActiveAdmin controller when load_and_authorize_resource
is removed from ApplicationController.
So what is the correct way to enable CanCanCan's authorization checks for my ActiveAdmin controllers? How should I integrate CanCanCan and ActiveAdmin so that non admin users can't access any ActiveAdmin resources?
I also posted this question to the ActiveAdmin mailing list but got no responses. Any help would be greatly appreciated.