设计current_user在空闲页面上不持久

时间:2015-04-06 02:01:09

标签: ruby-on-rails devise

我目前正在使用自定义设备注册控制器。奇怪的是,当页面暂时不使用时,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)中,将记录器放在设计中,并且它总是在此代码中停止。如何调试send方法?

1 个答案:

答案 0 :(得分:0)

哦,当你被困住时你问的事情......解决这个问题后我现在觉得很蠢。我甚至忘了提到系统是多租户的。

对于那些遇到同样问题的人,请检查租户:Apartment::Tenant.current。机会是,它恢复到public。至于它为什么这样做,我不知道。