有什么方法可以检查用户自 x 个月以来是否不活跃
Is there any way i can check if the user is not active since x months
我正在使用 rails 6 并设计用于身份验证。我知道这可以通过会话来完成,但不知道如何。我将感谢您的友好回应。
如果您所说的活跃是指用户已有 x 个月未登录。然后你可以检查 users
table 中的 last_sign_in_at
列。该列应由 Devise 创建。
months = 6 # Put your value here
if user.last_sign_in_at? && user.current_sign_in_at.blank?
user.last_sign_in_at < Time.now.months_ago(months)
end
如果用户从未登录过,您可以用类似的方式检查 created_at
字段。
首先在您的用户模型中实现此方法:
def active_in_last_6_months?
last_sign_in_at < 6.months.ago
end
然后在你的 controller/view:
current_user.active_in_last_6_months?
我正在使用 rails 6 并设计用于身份验证。我知道这可以通过会话来完成,但不知道如何。我将感谢您的友好回应。
如果您所说的活跃是指用户已有 x 个月未登录。然后你可以检查 users
table 中的 last_sign_in_at
列。该列应由 Devise 创建。
months = 6 # Put your value here
if user.last_sign_in_at? && user.current_sign_in_at.blank?
user.last_sign_in_at < Time.now.months_ago(months)
end
如果用户从未登录过,您可以用类似的方式检查 created_at
字段。
首先在您的用户模型中实现此方法:
def active_in_last_6_months?
last_sign_in_at < 6.months.ago
end
然后在你的 controller/view:
current_user.active_in_last_6_months?