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
AdminUser, here's how you can set up RailsAdmin to handle them separately:
Install RailsAdmin: If you haven't already installed RailsAdmin, add it to your Gemfile and run the bundle command:ruby
Then, run the following command to generate the RailsAdmin configuration file:bash
rails generate rails_admin:install
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
Configure RailsAdmin for AdminUser model: To configure RailsAdmin for the
AdminUsermodel, create a new initializer file for RailsAdmin. For example, create a file named
# 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
AdminUsermodel. For example, you might want to customize the list of visible fields, the label of the model, or hide certain actions for the
Ensure RailsAdmin recognizes the custom Devise models: RailsAdmin automatically detects Devise models based on the presence of certain methods (e.g.,
devise :registerable, etc.). If you have defined the two Devise models in separate files with appropriate Devise modules, RailsAdmin should recognize them.
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 (
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.