I\'m using devise which stores current_sign_in_at
and last_sign_in_at
datetimes.
But lets say a user logged in a month ago but last vie
To improve performance of the previous answer:
update_attribute
runs callbacks and updates updated_at
attribute, and update_column
notUpdated code:
before_action :set_last_seen_at, if: proc { user_signed_in? && (user.last_seen_at.nil? || user.last_seen_at < 15.minutes.ago) }
private
def set_last_seen_at
current_user.update_column(:last_seen_at, Time.now)
end
Devise plugin makes similar behaviour happen (just last seen, without optimizations): https://github.com/ctide/devise_lastseenable