Search code examples
ruby-on-railsrubypermissionsactiveadmincancancan

How to check cancan permission on ActiveAdmin custom page?


I've the following Ability:

can :manage, ActiveAdmin::Page, name: 'My Page'

And it is working fine, but I want to check if the user has the ability to manage this ActiveAdmin::Page in different pages. So, when I used the following:

can? :manage, ActiveAdmin::Page, name: 'My Page'

It returned true for any page even if it does not exist!


Solution

  • Finally, I figured out a way, it looks weird because it uses register_page but it is working:

    can? :manage, (ActiveAdmin::register_page 'My Page')