How to get Active Admin to work with Pundit after login

I have added config addirate authorization for my application

config.authorization_adapter = ActiveAdmin::PunditAdapter

      

When I login to admin@example.com account I get this error.

Pundit::NotDefinedError in Admin::Dashboard#index
unable to find policy AdminUserPolicy

Extracted source (around line #2):

insert_tag active_admin_application.view_factory["page"]

      

so i created these files in policy / active_admin folder

adminuser_policy.rb

module ActiveAdmin
class AdminUserPolicy < ApplicationPolicy
class Scope < Struct.new(:user, :scope)
  def resolve
    scope
  end
end
def home?
true
end

def index?
true 
end
def show?
true 
end
def new?
true
end

def create?
 true
end

def update?
true 
end

  def destroy?
    true 
 end
end

      

end

page_policy.rb

module ActiveAdmin
class PagePolicy < ApplicationPolicy
  class Scope < Struct.new(:user, :scope)
  def resolve
    scope
  end
 end
   def index?
      true
   end

   def show?
     true
   end
  end
end

      

What am I missing? Thanks for the help!

+3


source to share


1 answer


I found the answer!

After adding these two lines to the active initializer file admin

config.authorization_adapter = ActiveAdmin::PunditAdapter 

#this line sets the default policy to application_policy.rb
config.pundit_default_policy = "ApplicationPolicy"

      

I had to add this to dashboard.rb at app / admin / dashboard.rb



   def index
        authorize :dashboards, :index?
      end
    end

      

Then I created a file in the policies folder called dashboard_policy.rb and added this code

class DashboardPolicy < ApplicationPolicy
   def dashboard?
   true
  end
  def index?
   true
  end
 end

      

It worked!

+1


source







All Articles