登录后如何让 Active Admin 与 Pundit 一起工作
How to get Active Admin to work with Pundit after login
我已将配置专家 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
我错过了什么?感谢您的帮助!
我找到答案了!
将这两行添加到活动管理初始化程序文件后
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
然后我在我的策略文件夹中创建了一个名为 dashboard_policy.rb 的文件并添加了这段代码
class DashboardPolicy < ApplicationPolicy
def dashboard?
true
end
def index?
true
end
end
成功了!
我已将配置专家 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
我错过了什么?感谢您的帮助!
我找到答案了!
将这两行添加到活动管理初始化程序文件后
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.rbdef index
authorize :dashboards, :index?
end
然后我在我的策略文件夹中创建了一个名为 dashboard_policy.rb 的文件并添加了这段代码
class DashboardPolicy < ApplicationPolicy
def dashboard?
true
end
def index?
true
end
end
成功了!