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
Installing Libyaml for Ruby on a MAC Osx (Lion)
Multiple Level Nesting in Yaml
How to Cleanly Verify If the User Input Is an Integer in Ruby
Is Getting Converted as "\U0092" by Nokogiri in Ruby on Rails
Rails: Detecting User Agent Works in Development But Not Production
What Are the Differences Between Lazy, Greedy and Possessive Quantifiers
How to Force a Gem's Dependencies in Gemfile
Install Ruby 2.2 on MAC Osx Catalina with Ruby-Install
How to Handle Utf-8 Email Headers (Like Subject:) Using Ruby
How to Use Objects with Xsi:Types in Savon
Ruby on Rails: Search Form - Multiple Search Fields
Specifying Content Type in Rspec
Rails: How to Check If a Column Has a Value
Catching Timeout Errors with Ruby Mechanize
Why Does a Simple Thin Server Stop Responding at 16500 Requests When Benchmarking
Alter $Path in Vim/Macvim So as to Find the Right Ruby Binary
(New to Rails) Rails Server Error: Cannot Load Such File -- Bootsnap/Setup (Loaderror)