加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

ruby-on-rails – 如何让Active Admin在登录后与Pundit合作

发布时间:2020-12-17 02:07:36 所属栏目:百科 来源:网络整理
导读:我已将配置权威addapter授权添加到我的应用程序中 config.authorization_adapter = ActiveAdmin::PunditAdapter 当我使用admin@example.com凭据登录时,我收到此错误. Pundit::NotDefinedError in Admin::Dashboard#indexunable to find policy AdminUserPoli
我已将配置权威addapter授权添加到我的应用程序中

config.authorization_adapter = ActiveAdmin::PunditAdapter

当我使用admin@example.com凭据登录时,我收到此错误.

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

Extracted source (around line #2):

insert_tag active_admin_application.view_factory["page"]

所以我在policies / active_admin文件夹中创建了这些文件

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

结束

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

我错过了什么?谢谢您的帮助!

解决方法

我找到了答案!

将这两行添加到活动的admin初始化文件后

config.authorization_adapter = ActiveAdmin::PunditAdapter 

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

我必须将它添加到app / admin / dashboard.rb下的dashboard.rb

def index
  authorize :dashboards,:index?
end

然后我在我的policies文件夹中创建了一个名为dashboard_policy.rb的文件,并添加了此代码

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

这让它运作了!

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读