【问题标题】:ActiveAdmin Not Working Without DeviseActiveAdmin 没有设计就无法工作
【发布时间】:2017-10-24 19:08:01
【问题描述】:

所以我们刚刚完成了删除设计并推出了简单的bcrypt + cancancan 身份验证系统。

现在,我们还使用ActiveAdmin 作为我们与Devise 绑定的网络应用管理部分的解决方案。网络应用程序的那部分一切都被破坏了:)

我尝试了几种不同的方法来解决添加我们自己的身份验证方法的问题,但我找不到路由的解决方案以及还需要什么。

我们有一个应该是管理员用户的 AdminUser 模型。我确实将其“转换”为使用普通用户用于密码的列(在我们切换到 bcrypt 之后),但我完全不知道如何处理 ActiveAdmin。

【问题讨论】:

  • 这是一个广泛的问题,我发布了一个广泛的答案。如果您能更具体地说明您遇到的确切错误,我或许能够提供更准确的帮助。

标签: ruby-on-rails devise activeadmin


【解决方案1】:

您可能需要在config/initializers/active_admin.rb 中重新配置几项。

您可能需要定义身份验证方法:

# config/initializers/active_admin.rb

# == User Authentication
#
# Active Admin will automatically call an authentication
# method in a before filter of all controller actions to
# ensure that there is a currently logged in admin user.
#
# This setting changes the method which Active Admin calls
# within the application controller.
config.authentication_method = :authenticate_active_admin_user!

# app/controllers/application_controller.rb
def authenticat_active_admin_user!
  # Something that returns true if the current user has access to active admin
end

您可能还需要设置current_user 方法:

# config/initializers/active_admin.rb

# == Current User
#
# Active Admin will associate actions with the current
# user performing them.
#
# This setting changes the method which Active Admin calls
# (within the application controller) to return the currently logged in user.
config.current_user_method = :current_user

# app/controllers/application_controller.rb
def current_user
  # returns the current logged in user.  Devise provides this automatically. You will need to replace that functionality.
end

以上只是 Active Admin 初始化程序中影响登录和身份验证的两件事。我建议通读一遍并查看与用户身份验证和授权相关的所有其他配置。初始化程序在 cmets 中有很好的文档记录,并且在 Active Admin homepage 中有大量文档。您可能会发现您需要替换活动管理员用于身份验证和授权的其他一些方法。

最后,确保您的 CanCanCan Ability 类能够访问当前用户。如果您的控制器没有将正确的用户传递给它,那么它将阻止访问。

【讨论】:

    猜你喜欢
    • 2019-01-12
    • 2011-01-14
    • 2015-06-27
    • 1970-01-01
    • 1970-01-01
    • 2020-04-07
    • 1970-01-01
    • 1970-01-01
    • 2015-06-04
    相关资源
    最近更新 更多