ActiveAdmin + CanCanCan errors with: protected method `authorize! 'for <Every ActiveAdmin Controller>

I have problems with ActiveAdmin to work with CanCanCan. I'm using version 1.9.2 and CanCanCan ActiveAdmin version 1.0.0.pre in Annex Rails 4. After setting capability class and enable authorization checking for the rest of my application, adding load_and_authorize_resourceand check_authorizationmy the ApplicationController, I get an error message

protected method 'authorize!' called for #<Activeadmin::<SomeControler>> (NoMethodError)

After some searching, I came across this this GitHub problem, which looks exactly like the problem I am facing. However, the solution does not work for me. In config / initializers / active_admin.rb, I have, among other things: ... config.authorization_adapter = ActiveAdmin::CanCanAdapter ... I also guaranteed that I have no links to controller.authorize_resourceany ActiveAdmin controller, but I still get an error protected method authorize! ...when I try to access any ActiveAdmin resources from my integration tests.

After several trial and error and more searching, I found that calling load_and_authorize_resourcefrom ApplicationController is not recommended, and that the ActiveAdmin authorization_adapter parameter for CanCanAdapter, as I did above, should automatically enable CanCanCan authorization checks in ActiveAdmin, but check_authorizationfailed because the resource was not allowed for each ActiveAdmin controller when it load_and_authorize_resourceis removed from the ApplicationController.

So, what is the correct way to enable CanCanCan authority checks for my ActiveAdmin controllers? How can I integrate CanCanCan and ActiveAdmin so that non-admin users cannot access ActiveAdmin resources?

I also posted this question on the ActiveAdmin mailing list, but received no answers. Any help would be greatly appreciated.

+4
1

, . ActiveAdmin CanCanAdapter CanCanCan check_authorization. @_authorized, , ActiveAdmin . , ActiveAdmin IS , check_authorization , ActiveAdmin . , , unless: check_authorization, ActiveAdmin. check_authorization , , CanCanAdapter , ActiveAdmin IS .

, ApplicationController, , - :

class ApplicationController < ActionController::Base
  ...
  check_authorization unless: :activeadmin_resource?
  ...
  private

  def activeadmin_resource?
    self.class.ancestors.include? ActiveAdmin::BaseController
  end
end
+5

All Articles