Rails 3 - Can Active_admin use an existing user model?

前端 未结 4 1021
闹比i
闹比i 2020-12-22 23:05

Can Active Admin use my current Devise user model? It already has a column named admin, and if it\'s true, I\'d l

4条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-22 23:38

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

    rails generate active_admin:install --skip-users
    

    Then in your 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!
    

    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

    Hope this helps.

提交回复
热议问题