Nun*_*uno 5 ruby-on-rails devise apartment-gem
基本上我想要实现的是:
但是,我的问题是我不知道如何从Generic Elevator提供的请求(Rack :: Request)对象中检索当前用户.有关如何操作的任何提示或有任何其他方式来获取当前用户没有请求?
我正在使用设计进行身份验证.
对于那些与我有同样问题的人,这是我的解决方案.
#My excluded models
config.excluded_models = %w{ User }
Rails.application.config.middleware.use 'Apartment::Elevators::Generic', lambda { |request|
tenant_name = nil
if request.env['rack.session']['warden.user.user.key'] != nil
tenant_name = User.find(request.env['rack.session']['warden.user.user.key'][0][0]).account.name
end
return tenant_name
}
Run Code Online (Sandbox Code Playgroud)
但是我不确定这是100%防故障,所以如果我发现它有问题,我会发布更新.
| 归档时间: |
|
| 查看次数: |
1340 次 |
| 最近记录: |