我一直在使用设计进行身份验证,并可以在我的应用程序中进行授权.该应用程序适用于他们.但现在我想使用主动管理员来管理我的应用程序中已经被设计和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
希望它可以帮助你,也许还有其他人.
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。