Merging ActiveAdmin users with existing user model

后端 未结 2 622
时光说笑
时光说笑 2021-02-14 17:09

I\'ve set up ActiveAdmin early in my project and used the default admin_users model for authentication. I\'ve since used Devise to set up a separate User model and

相关标签:
2条回答
  • 2021-02-14 17:20

    For a quick code block of how to do this using an existing "User" model with activeadmin, the answer is actually really easy. In the ApplicationController:

    class ApplicationController < ActionController::Base
        def authenticate_admin_user! #use predefined method name
          redirect_to '/' and return if user_signed_in? && !current_user.is_admin? 
          authenticate_user! 
        end 
        def current_admin_user #use predefined method name
          return nil if user_signed_in? && !current_user.is_admin? 
          current_user 
        end 
    end
    

    And just use what Devise already has set up for authentication. The redirect_to is where you want to send users who ARE signed in and DO NOT have administrative privileges.

    0 讨论(0)
  • 2021-02-14 17:21

    ActiveAdmin let's you define your own authentication methods. You can migrate your user tables to have an additional admin column and mark the existing admins as such in it, then set your authentication methods (as specified) in config/initializers/active_admin.rb.

    0 讨论(0)
提交回复
热议问题