To use multiple Devise models with RailsAdmin, you need to configure RailsAdmin to handle each Devise model separately. RailsAdmin has built-in support for Devise, but when you have multiple Devise models, you'll need to customize the configurations for each model.

Assuming you have two Devise models named User and AdminUser, here's how you can set up RailsAdmin to handle them separately:

  1. Install RailsAdmin: If you haven't already installed RailsAdmin, add it to your Gemfile and run the bundle command:

    gem 'rails_admin'

    Then, run the following command to generate the RailsAdmin configuration file:

    rails generate rails_admin:install
  2. Configure RailsAdmin for User model: By default, RailsAdmin is set up to handle the default Devise model, which is usually named User. You don't need to do anything special for this model. RailsAdmin should work out of the box for the User model.

  3. Configure RailsAdmin for AdminUser model: To configure RailsAdmin for the AdminUser model, create a new initializer file for RailsAdmin. For example, create a file named rails_admin_admin_user.rb in the config/initializers directory:

    # config/initializers/rails_admin_admin_user.rb RailsAdmin.config do |config| config.model AdminUser do # Custom configuration for AdminUser model (if needed) end end

    In the above code, you can add any custom configuration specific to the AdminUser model. For example, you might want to customize the list of visible fields, the label of the model, or hide certain actions for the AdminUser model.

  4. Ensure RailsAdmin recognizes the custom Devise models: RailsAdmin automatically detects Devise models based on the presence of certain methods (e.g., devise :database_authenticatable, devise :registerable, etc.). If you have defined the two Devise models in separate files with appropriate Devise modules, RailsAdmin should recognize them.

  5. Start the Rails server: After making the necessary configuration changes, start the Rails server, and you should be able to access RailsAdmin with support for both Devise models.

Please note that the above steps assume that you have set up Devise correctly for both models (User and AdminUser). Ensure that both models are authenticating users as intended before integrating RailsAdmin.

Additionally, you can further customize the behavior of RailsAdmin for each model by exploring the extensive configuration options provided by RailsAdmin. The RailsAdmin documentation provides detailed information about all available configuration options and customization possibilities.

Have questions or queries?
Get in Touch