问题
How do you implement authentication with the rails_admin gem when you are not using devise e.g. you have rolled your own authentication?
回答1:
In config/initializers/rails_admin.rb
include a config.authenticate_with
block and place your authentication logic there. It should raise an exception if the user is not authorised to use rails_admin. Here is a simple example:
RailsAdmin.config do |config|
config.authenticate_with do
raise 'You must be admin' unless signed_in? && current_user.admin?
end
end
If you want to follow the rails_admin
instructions for the cancancan
gem then also add the following config line:
config.current_user_method(&:current_user)
来源:https://stackoverflow.com/questions/38966731/using-roll-your-own-authentication-with-the-rails-admin-gem