onlineable
Gem for Rails application - provides you list of online users (for authentication gem 'devise') for ActiveRecord ou Mongoid.
Installation
Add this line to your application's Gemfile:
gem 'onlineable'
And then execute:
$ bundle install
Next you have to run this to make it install the initializer
$ rails g onlineable:install
*Note: if you are doing this on a Heroku server run the following command:
$ heroku run rails g onlineable:install
Do not do a run:detached as it prompts you and you will have to manually
terminate the process if you run:detached.
Usage
For using functionality add to ApplicationControler:
before_action { |c| current_usuario.track_online unless current_usuario.nil?}
This will make the app consider the online user while they interact with the application.
and In your template, add: onlineable-by-todd for the current device line at the end, and if you want to change the time (in seconds or minutes) that a user is considered online add below: time seconds: n or time minutes: n, the default is seconds: 30.
class User < ActiveRecord::Base
devise ..., :onlineable
time seconds:30 #or
time minutes:2
end
Helper for online users list (for the whole list, not just an individual):
Model.who_online, e.g. User.who_online, Admin.who_online
To see if a user is online you would run something like this:
User.who_online.include?(user)
Now you can override the default time to check for user activity. It defaults
to 15 seconds (i.e. if the user hasn't done anything for 15 seconds they are
not considered online). To override this with say 30 seconds you would do the
following:
User.who_online(30).include?(user)
I have also modified the code to work more easily with RedisToGo on Heroku.
It now works with RedisToGo on Heroku, it needed the password to be parsed,
now it is.
Requirement