Rails 3 - Active_admin 可以使用现有的用户模型吗? [英] Rails 3 - Can Active_admin use an existing user model?

查看:15
本文介绍了Rails 3 - Active_admin 可以使用现有的用户模型吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Active Admin 可以使用我当前的 Devise 用户模型吗?它已经有一个名为 admin 的列,如果它是 true,我想在转到 /admin 时绕过 Active admin 登录.

Can Active Admin use my current Devise user model? It already has a column named admin, and if it's true, I'd like to bypass the Active admin login, when going to /admin.

这可能吗?

当前路线:

#Active admin
ActiveAdmin.routes(self)

#Devise
devise_for :admin_users, ActiveAdmin::Devise.config
devise_for :users, :path => "account"

其余基本都是标准的Devise + Active admin

The rest is basically standard Devise + Active admin

推荐答案

是的,你可以这样做,当 运行生成器 跳过用户模型创建:

Yes you can do that, when running the generator skip the user model creation:

rails generate active_admin:install --skip-users

然后在您的 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 controller.
config.authentication_method = :authenticate_admin!

取消注释 config.authentication_method 并为您的管理员提供您的身份验证方法,例如:

uncomment config.authentication_method and provide your authentication method for your admin, for example:

# app/controllers/application_controller.rb
def authenticate_admin!
 redirect_to new_user_session_path unless current_user.is_admin?
end

重启你的服务器,它应该可以工作了.另请查看活动管理配置

Restart your server and It should be working. Also Take a look to Active Admin Configuration

希望这会有所帮助.

这篇关于Rails 3 - Active_admin 可以使用现有的用户模型吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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