我目前正在开发一个具有自定义注册控制器的系统。奇怪的是,当页面在一段时间内不被使用时,current_user变量会获得nil值。我将日志放在系统的不同部分,并发现在以下方法中,没有设置资源:
# Authenticates the current scope and gets the current resource from the session.
def authenticate_scope!
send(:"authenticate_#{resource_name}!", force: true)
self.resource = send(:"current_#{resource_name}")
end当我检查会话时,它突然改变了值。
Sign-in action:
{"session_id"=>"5b714b8718d1c83d3a19f83355f98c69", "user_return_to"=>"/users/edit", "flash"=>#<ActionDispatch::Flash::FlashHash:0x007ff2426a9208 @used=#<Set: {:notice}>, @closed=false, @flashes={:notice=>"Signed in successfully."}, @now=nil>, "warden.user.user.key"=>[[46], "$2a$10$9x4tg9SvShVBgGPejhbliu"], "_csrf_token"=>"gOqNojt6SdyVs69kVZcYYBrrAWIB8U07MqWs7rfqbO8="}
No idle time:
{"session_id"=>"5b714b8718d1c83d3a19f83355f98c69", "user_return_to"=>"/users/edit", "warden.user.user.key"=>[[46], "$2a$10$9x4tg9SvShVBgGPejhbliu"], "_csrf_token"=>"gOqNojt6SdyVs69kVZcYYBrrAWIB8U07MqWs7rfqbO8="}
With idle time:
{"session_id"=>"5b714b8718d1c83d3a19f83355f98c69", "user_return_to"=>"/users/edit", "_csrf_token"=>"gOqNojt6SdyVs69kVZcYYBrrAWIB8U07MqWs7rfqbO8=", "flash"=>#<ActionDispatch::Flash::FlashHash:0x000000066e9078 @used=#<Set: {:alert}>, @closed=false, @flashes={:alert=>"You need to sign in or sign up before continuing."}, @now=nil>}如何跟踪会话更改?或者,有没有一种方法可以在它发生变化时进行检查?
我刚刚检查了gemfile,它包含了devise-async。这有影响吗?
其中的精华是:gem 'rails', '3.2.17', gem 'devise', '3.2.3', gem 'devise-async', '0.9.0'
在被困在send(:"authenticate_#{resource_name}!", :force => true)之后,我不确定如何进一步追踪这一点。我将包放在项目(./bundle)中,将记录器放在devise中,它总是在此代码中停止。如何调试send方法?
发布于 2015-04-08 08:35:13
哦,当你被卡住的时候,你所问的事情...解决了这个问题后,我现在觉得自己很愚蠢。我甚至忘了提这个系统是多租户的。
因此,对于那些有相同问题的人,请查看tenant:Apartment::Tenant.current。很有可能,它会恢复为public。至于为什么会这样,我不知道。
https://stackoverflow.com/questions/29464396
复制相似问题