2
我在rails会话上使用ruby来存储用户cookie以保持登录状态,因此我不能只在登录后更新last_seen列。我试图找出最好的方法来查明用户是否在最后一天活跃起来。这是我迄今为止,但我不知道是否有一个更好的办法:查找登录用户的上一次活动时间
class ApplicationController
before_filter :update_last_seen
private
def update_last_seen
if (DateTime.now - 1.day) < current_user.last_seen
current_user.last_seen = DateTime.now
current_user.save
end
end
end
这里的问题是,它会被调用每个请求。有什么办法可以避免这种情况?当用户处于活动状态时,会话cookie是否会以某种方式更新?
好的,谢谢,它看起来像update_last_request_at!可能是Authlogic使用的方法:http://github.com/qoobaa/sms/blob/41e2ee0ea1425b44db29150a940f153aaaac50d7/vendor/gems/authlogic-1.4.1/lib/authlogic/session/timeout.rb。 – TenJack 2010-02-28 15:39:05