且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Rails 3 - Active_admin 可以使用现有的用户模型吗?

更新时间:2023-12-02 23:23:22

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

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

希望这会有所帮助.