How to get Active Admin to work with Pundit after login

后端 未结 1 1676
你的背包
你的背包 2021-01-05 15:51

I\'ve added the configuration pundit addapter authorization to my application

config.authorization_adapter = ActiveAdmin::PunditAdapter

Wh

相关标签:
1条回答
  • 2021-01-05 16:50

    I found the answer!

    After adding these two lines to the active admin initializer file

    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 under app/admin/dashboard.rb

    def index
      authorize :dashboards, :index?
    end
    

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

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

    That got it working!

    0 讨论(0)
提交回复
热议问题