“Who’s Online” using Devise in Rails

Simply add after_filter in ApplicationController

after_filter :user_activity

private

def user_activity
  current_user.try :touch
end

Then in user model add online? method

def online?
  updated_at > 10.minutes.ago
end

Also u can create scope

scope :online, lambda{ where("updated_at > ?", 10.minutes.ago) }

Leave a Comment