Ruby on rails 你能用Desive和Active Admin禁用权威吗?

Ruby on rails 你能用Desive和Active Admin禁用权威吗?,ruby-on-rails,devise,activeadmin,pundit,Ruby On Rails,Devise,Activeadmin,Pundit,我有一个现有的Rails应用程序,它在用户模型上运行Desive/Pundit 我遵循了: 我现在不需要授权-Desive for authentication就可以了。我可以只“关闭”活动管理员的权威吗 更新 这是超级猴子补丁: after_action :verify_policy_scoped, only: [:index] if controller_path.split('/').first == "admin" 这很管用,但我觉得不太理想 config.authenticati

我有一个现有的Rails应用程序,它在用户模型上运行Desive/Pundit

我遵循了:

我现在不需要授权-Desive for authentication就可以了。我可以只
“关闭”
活动管理员的权威吗

更新

这是超级猴子补丁:

after_action :verify_policy_scoped, only: [:index] if controller_path.split('/').first == "admin"
这很管用,但我觉得不太理想

config.authentication_method = false  
config.current_user_method   = false

在config/initializers/active_admin.rb中,您可以尝试设置授权适配器

设置您自己的AuthorizationAdapter很容易!以下示例显示如何设置授权适配器类并将其绑定到Active Admin:

# app/models/only_authors_authorization.rb
class NotAdminAuthorization < ActiveAdmin::AuthorizationAdapter

  def authorized?(action, subject = nil)
   false
  end

end
以及其他可以定义名称空间切换的选项

ActiveAdmin.setup do |config|
  config.namespace :admin do |ns|
    ns.authorization_adapter = "NotAdminAuthorization"
  end
  config.namespace :my_user do |ns|
    ns.authorization_adapter =  ActiveAdmin::PunditAdapter
  end
end
那么像这样

ActiveAdmin.register Post, namespace: :my_user

这会禁用身份验证-我想禁用授权。我是说,如果AdminUser登录,默认情况下他们是经过授权的。这不起作用-我仍然会收到无休止的Pundit PolicyScoping和Authorization Errors您定义了命名空间吗?对其他用户使用authorization\u adapter=ActiveAdmin::PunditAdapter我对这个切换的作用感到困惑。现在我有了config.authorization\u adapter=ActiveAdmin::PunditAdapter集。我在AA中进入的每一页都会导致:```Pundit::NotDefinedError at/admin/dashboard无法找到的策略
AdminUserPolicy
`#````
ActiveAdmin.register Post, namespace: :my_user