Rails - How to Check for Online Users

Rails - How to check for online users?

The simplest thing would be to add a last_online timestamp to your User model, then define a scope for user called online_now

class User < ActiveRecord::Base
def self.online_now
where("last_online > ?", 15.minutes.ago)
end
end

To view all users online in a Ruby on rails Application

You can set a before_filter on the application_controller that sets an 'online_at' attribute. Then you can display all users who were online in the last 5 mins.

How to track online users in Rails?

If you are using the active_record_store for your sessions, you can try something like this:

sessions = CGI::Session::ActiveRecordStore::Session.find(:all, :conditions => ["updated_at >= ?", 15.minutes.ago], :order => "created_at ASC")
sessions.each do |session|
if session.data[:user]
online_users << User.find(session.data[:user])
end
end

Who's Online using Devise in Rails

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.

Check for active users in rails if the users stays in one page and dont click through the app

Presumably they interact in some way with the page (ajax perhaps?) so you'll need to detect those interactions and use them to determine if the user is idle or not. You could use javascript's onbeforeunload to determine when they have left the page.

Find online users using devise and rails 3

Google and stackoverflow are your friends:

There appears to be a gem for this and has been asked a lot.

"Who's Online" using Devise in Rails



Related Topics



Leave a reply



Submit