My users need to login to run the app I''m building. I''d like to give them an "Other users currently active:" piece of information. I could track it myself in the database based on login/logout, but that doesn''t really count for people just leaving the computer logged in and never coming back. Does Rails have an API for me to monitor sessions and take a peek at their info? I''m googling as best I can but I have to sift through all the references to developer conferences with "ruby sessions" :) D -- Posted via http://www.ruby-forum.com/.
Duane MOrin wrote:> My users need to login to run the app I''m building. I''d like to give > them an "Other users currently active:" piece of information. I could > track it myself in the database based on login/logout, but that doesn''t > really count for people just leaving the computer logged in and never > coming back. Does Rails have an API for me to monitor sessions and take > a peek at their info?That can be done (see my post about "SessionCleanup" -- a look at the software will give you a good idea how to go about it). BUT -- it''s not any more useful than tracking logins and logouts. Sessions can''t tell you when somebody wanders away from a computer and doesn''t come back. Probably the best approach would be to keep a database record of people presently logged in with a "last_activity_time" field, and update it whenever they performed some activity. Then you could present a list of everyone who had done something in the past ten minutes, for example. --Al Evans -- Posted via http://www.ruby-forum.com/.
On 6/22/06, Al Evans <anejr@alevans.com> wrote:> Probably the best approach would be to keep a database record of people > presently logged in with a "last_activity_time" field, and update it > whenever they performed some activity. Then you could present a list of > everyone who had done something in the past ten minutes, for example.This would work pretty easily. Add a column to the sessions table, then a before_filter in application.rb to update the field. This wouldn''t work if your users viewed only cached pages for X consecutive minutes, but it should be close enough (if that''s even an issue). Pat
Sure, here''s how. Create a file called dump_sessions (no .rb extension) in your /script subdirectory. Paste the following code: #!/usr/bin/env ruby require ''pp'' require File.dirname(__FILE__) + ''/../config/environment'' Dir[''app/models/**/*rb''].each{|f| require f} pp Dir[''./tmp/sessions/ruby_sess*''].collect {|file| [file, Marshal.load(File.read(file))] } Now, from the root of your app, type ruby script/dump_sessions and there you have it. :) David> My users need to login to run the app I''m building. I''d like to give > them an "Other users currently active:" piece of information. I could > track it myself in the database based on login/logout, but that doesn''t > really count for people just leaving the computer logged in and never > coming back. Does Rails have an API for me to monitor sessions and take > a peek at their info? > > I''m googling as best I can but I have to sift through all the references > to developer conferences with "ruby sessions" :) > > D > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
straightflush@gmail.com
2006-Jun-23 01:27 UTC
[Rails] Can I peek at all "active sessions"?
If you use DB Sessions you can add a before filter in application.rb to set some session variable, make sure you have a DB column updated_at, and then just query that field. adam On 6/22/06, David M <lists@codecharter.com> wrote:> > Sure, here''s how. Create a file called dump_sessions (no .rb extension) > in your /script subdirectory. Paste the following code: > > #!/usr/bin/env ruby > require ''pp'' > require File.dirname(__FILE__) + ''/../config/environment'' > Dir[''app/models/**/*rb''].each{|f| require f} > pp Dir[''./tmp/sessions/ruby_sess*''].collect {|file| [file, > Marshal.load(File.read(file))] } > > Now, from the root of your app, type ruby script/dump_sessions and there > you have it. :) > > David > > > My users need to login to run the app I''m building. I''d like to give > > them an "Other users currently active:" piece of information. I could > > track it myself in the database based on login/logout, but that doesn''t > > really count for people just leaving the computer logged in and never > > coming back. Does Rails have an API for me to monitor sessions and take > > a peek at their info? > > > > I''m googling as best I can but I have to sift through all the references > > to developer conferences with "ruby sessions" :) > > > > D > > > > -- > > Posted via http://www.ruby-forum.com/. > > _______________________________________________ > > Rails mailing list > > Rails@lists.rubyonrails.org > > http://lists.rubyonrails.org/mailman/listinfo/rails > > > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060623/dc6a0a43/attachment.html