"Who's Online" using Devise in Rails

Solution 1:

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) }

Solution 2:

https://github.com/ctide/devise_lastseenable

You can use this gem that I wrote to store the 'last_seen' timestamp of a user. From there, it's pretty trivial to display the users who were last_seen in the last 5 or 10 minutes.