Using roll your own authentication with the rails_admin gem

倾然丶 夕夏残阳落幕 提交于 2019-12-12 01:25:45

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!