使用ActiveAdmin处理多种管理员类型的登录 [英] Handling more than one admin types login with ActiveAdmin

查看:130
本文介绍了使用ActiveAdmin处理多种管理员类型的登录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个需要登录的三种用户类型(用户,代理,管理员)的应用程序,并且需要不同的devise模块。

I have an application requiring three User types(User, Agent, Admin) with login and requiring different devise modules.

                        User    AgentAdmin  AdminUser

confirmable              Yes        Yes         No
lockable                 Yes        Yes         No
timeoutable               No        Yes         Yes
Omniauthable             Yes        No          No
database_authenticatable Yes        Yes         Yes
recoverable              Yes        Yes         No
rememberable             Yes        Yes         No
trackable                Yes        Yes         Yes
validatable              Yes        Yes         Yes

根据用户的类型,这些用户可能还会有其他列。因此,我想根据它们的类型创建不同的表。

Further these users may have additional columns based on their type. So, I want to create different tables based on their type.

根据我的要求,我决定处理 AgentAdmin AdminUser ActiveAdmin 和不同的命名空间( AdminUser 的管理员, AgentAdmin 的代理)。我已经为这两个配置了 authentication_method current_user_method logout_link_path

Depending on my requirements, I decided to handle AgentAdmin and AdminUser with ActiveAdmin with different namespaces(admin for AdminUser , agent for AgentAdmin). I have configured authentication_method, current_user_method and logout_link_path for both these namespaces as below.

config.load_paths = [File.join(Rails.root,'app','admin'), File.join(Rails.root,'app','agent')]

config.namespace :admin do |admin|
  admin.authentication_method = :authenticate_admin_user!
  admin.current_user_method = :current_admin_user
  admin.logout_link_path = :destroy_admin_user_session_path
end

config.namespace :agent do |agent|
  agent.authentication_method = :authenticate_agent_admin!
  agent.current_user_method = :current_agent_admin
  agent.logout_link_path = :destroy_agent_admin_session_path
end

我的 routes.rb 中有以下代码:

devise_for :agent_admins, ActiveAdmin::Devise.config
devise_for :admin_users, ActiveAdmin::Devise.config
ActiveAdmin.routes(self)

这仅为 admin_users 生成登录路径。
如果我在active_admin.rb配置文件中设置 config.default_namespace =:agent ,则 agent_admin 会生成,但不会生成 admin_users

This generates login paths only for admin_users. If I set config.default_namespace = :agent in active_admin.rb config file, the login path for agent_admin is generated, but not admin_users.

所有其他ActiveAdmin路径通常都为两个名称空间生成。

All other ActiveAdmin paths are generated normally for both the namespaces.

如何解决,同时生成两个 activedmin 处理的登录路径?

How can I solve, to generate both the login paths handled by activedmin?

推荐答案

devise_for :agent_admins, ActiveAdmin::Devise.config.merge({path: '/agent'})
devise_for :admin_users, ActiveAdmin::Devise.config
ActiveAdmin.routes(self)

此问题已解决。

这篇关于使用ActiveAdmin处理多种管理员类型的登录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆