如何为rails_admin使用多设计模型

时间:2015-05-16 07:36:57

标签: ruby-on-rails devise rails-admin

我有两个设计模型,useradmin,当useradmin通过登录表单登录时,会重定向到/admin

我已阅读rails_admin wiki,但似乎只是关于单一设计模型的配置,我可以定义多个监护人范围如下:

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

1 个答案:

答案 0 :(得分:0)

You can add more than one devise model. Here is an example (with a checksum authentication):

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

You class Admin::ChecksumAuthenticatable (for example) needs to inherit from ::Devise::Strategies::Base. Then define all methods you want and overwrite authenticate! method:

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