假设用户在网站上花费了很长时间。
如何获取用户的上次事件时间。
上次事件时间是指用户最后一次请求(访问页面。用户甚至不需要更新或创建新记录)到应用程序的时间戳。
用户可能在大约一个小时前登录。然后他还在我的网站上上网。
我想要用户发送的最后一个请求的时间。
是否可以?
设计有 current_sign_in_at 但不是上次事件时间。
最佳答案
我实现这个的方法是添加一个 last_active_at
日期时间列到用户模型,然后在我的 Controller 中放入一些东西:
class ApplicationController
before_filter :record_user_activity
private
def record_user_activity
if current_user
current_user.touch :last_active_at
end
end
end
关于ruby-on-rails - 使用Devise时如何获取用户上次活跃时间?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14131040/