我一直在使用设计进行身份验证,并可以在我的应用程序中进行授权.该应用程序适用于他们.但现在我想使用主动管理员来管理我的应用程序中已经被设计和cancan使用的所有用户. Active admin为用户创建自己的admin_users表.如何让active_admin使用以前使用的用户和角色表? thanx的帮助.
解决方法
如果您已经创建了users表,那么您应该跳过创建此表.
运行:
rails generate active_admin:install --skip-users
并且不要忘记运行:
bundle exec rake db:migrate
尝试更改config / initializers / active_admin.rb文件中的身份验证方法.还要确保已创建current_admin_user方法,否则,您可以将其修改为设计默认值(current_user方法).
config.logout_link_method = :delete
以及注销操作的路径路径.
config.logout_link_path = :destroy_user_session_path
为了更好地理解authenticate方法,我粘贴了我的app / controllers / application_controller.rb相关代码:
class ApplicationController < ActionController::Base protect_from_forgery # # redirect registered users to a profile page # of to the admin dashboard if the user is an administrator # def after_sign_in_path_for(resource) resource.role == 'admin' ? admin_dashboard_path : user_path(resource) end def authenticate_admin_user! raise SecurityError unless current_user.try(:role) == 'admin' end rescue_from SecurityError do |exception| redirect_to root_path end end
希望它可以帮助你,也许还有其他人.