cat*_*cat 5 ruby-on-rails devise ruby-on-rails-3
假设用户在网站上花了很长时间.
如何获取用户上次活动时间.上次活动时间表示请求(访问该页面.用户甚至不需要更新或创建新记录)到应用程序的用户的最后时间戳.
用户可能在大约一小时前签约.然后他仍然在我的网站上网冲浪.我想要用户发送的最后一次请求的时间.
可能吗?
设计有current_sign_in_at但不是最后一个活动时间.
小智 20
我实现这个的方法是last_active_at在User模型中添加一个datetime列,然后在我的控制器中添加一些东西:
class ApplicationController
before_filter :record_user_activity
private
def record_user_activity
if current_user
current_user.touch :last_active_at
end
end
end
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3089 次 |
| 最近记录: |