Pundit permission on activeadmin user page

In a Rails 4 application labeled activeadmin (current main branch), I use Pundit for authorization. It works well for ressources, but I am unable to get it to work on pages.

Given for example:

ActiveAdmin.register_page "Home" do content do para "some text" end end 

How do I allow it for a specific user?

After reading the Pundit readme, I tried using the following code, but it does not work.

 class HomePolicy < Struct.new(:user, :home) def index? true end def show? true end end 

Any idea?

+5
source share
1 answer

Here is an example of the policy that I use for the toolbar. I placed it under policies/active_admin/page_policy.rb . Maybe this can help?

 class ActiveAdmin::PagePolicy attr_reader :user, :record def initialize(user, record) @user = user @record = record end def show? case record.name when 'Dashboard' true else user.admin? end end end 
+6
source

All Articles