How to use multi-user model for rails_admin

I have two development models: user

and admin

, When user

and admin

are registered in the login form, then redirected to/admin

I have read the rails_admin wiki but it only seems to be about setting up a single design model. Can I define a multiple observation scope as below:

RailsAdmin.config do |config|
  config.authenticate_with do
    warden.authenticate! scope: [:user,:admin]
  end
  config.current_user_method(&:current_user)
  config.current_admin_method(&:current_admin)
end

      

+3


source to share


1 answer


You can add multiple models. Here's an example (with checksum verification):

# initilizer/devise.rb
Devise.setup do |config|
  config.warden do |manager|
    manager.strategies.add :admin, Admin::ChecksumAuthenticatable
  end
end

      



Your class Admin::ChecksumAuthenticatable

(for example) must inherit from ::Devise::Strategies::Base

. Then define all the required methods and overwrite the method authenticate!

:

def authenticate!
  admin = Admin.from_checksum_for_auth!(checksum)
  # from_checksum_for_auth! is defined on Admin model and check checksum validity
  success! admin
end

      

0


source







All Articles