我实施了这个解决方案 How to Setup Multiple Devise User Models
然而,设计后的flash消息无法正常工作,我尝试重新设置此行 flash.clear但仍然没有显示flash消息,
# ../controllers/concerns/accessible.rb
module Accessible
extend ActiveSupport::Concern
included do
before_action :check_user
end
protected
def check_user
flash.clear
if current_tenant
redirect_to(authenticated_tenant_root_path) && return
elsif current_user
redirect_to(authenticated_user_root_path) && return
end
end
end
答案 0 :(得分:0)
您是否尝试更改您的Devise本地化?您的模型可能没有合适的钥匙。它应该是这样的:
en:
devise:
failure:
user:
invalid: 'Welcome user, you are signed in.'
not_found: 'User not found.'
admin:
invalid: 'Invalid admin credentials'
not_found: 'Admin not found'
希望这有帮助吗?
答案 1 :(得分:0)
devise stored_location_for为我修复了它,在这里找到了实例方法http://www.rubydoc.info/github/plataformatec/devise/Devise/Controllers/StoreLocation
module Accessible
extend ActiveSupport::Concern
included do
before_action :check_user
end
protected
def check_user
if current_tenant
redirect_to stored_location_for(:tenant) ||
authenticated_tenant_root_url && return
elsif current_user
redirect_to stored_location_for(:user) ||
authenticated_user_root_url && return
end
end
end