# app/controllers/application.rb
after_action :user_activity
private
def user_activity
current_user.try :touch
end
# app/models/user.rb
ONLINE_PERIOD = 5.minutes
scope :online, -> { where('updated_at > ?', ONLINE_PERIOD.ago) }
def online?
updated_at > ONLINE_PERIOD.ago
end
User.online # все пользователи онлайн