"User last online" 在 <time> 使用设计?
"User last online" at <time> using devise?
是否有任何 easy/native 方法来显示用户上次使用标准 rails 应用程序在其个人资料页面上在线的时间?
我能得到的最接近的是
<%= @user.current_sign_in_at.to_s %>
这显示了上次登录的时间(这可能与用户上次检查网站的时间有很大不同 - 即他们最后一次 'online' 可以这么说)。例如,如果用户在过去 90 秒内的任何时间使用该网站,我想显示一个小绿灯,但如果使用他们最后一次登录的时间,那将不准确。
在用户的 table last_seen_at
中添加一列,并在每次使用 touch 时更新它。
class ApplicationController
before_action :record_last_seen_at
private
def record_last_seen_at
if current_user
current_user.touch :last_seen_at
end
end
end
是否有任何 easy/native 方法来显示用户上次使用标准 rails 应用程序在其个人资料页面上在线的时间?
我能得到的最接近的是
<%= @user.current_sign_in_at.to_s %>
这显示了上次登录的时间(这可能与用户上次检查网站的时间有很大不同 - 即他们最后一次 'online' 可以这么说)。例如,如果用户在过去 90 秒内的任何时间使用该网站,我想显示一个小绿灯,但如果使用他们最后一次登录的时间,那将不准确。
在用户的 table last_seen_at
中添加一列,并在每次使用 touch 时更新它。
class ApplicationController
before_action :record_last_seen_at
private
def record_last_seen_at
if current_user
current_user.touch :last_seen_at
end
end
end