Hi,
I''m using ActiveRecordStore to track user sessions.
I''ve used as a base the next sources:
- http://blog.levicole.com/articles/category/ror
- http://matt-beedle.com/2006/12/13/rails-how-to-find-out-who-is-online/
- http://www.williambharding.com/blog/?p=99
This is what I currently do:
IN SESSION CONTROLLER
def create
self.current_user = User.authenticate(params[:login],
params[:password])
if logged_in?
session.model.user_id = current_user.id
if params[:remember_me] == "1"
self.current_user.remember_me
end
current_user.update_attribute(:online, true)
redirect_back_or_default(''/'')
else
render :action => ''new''
end
end
def destroy
self.current_user.forget_me if logged_in?
reset_session
current_user.update_attribute(:online, false)
redirect_back_or_default(''/'')
end
FINDING SESSIONS
@online_sessions = CGI::Session::ActiveRecordStore::Session.find( :all,
:conditions => [ "updated_at > ? and user_id is not null",
Time.now() -
10.minutes ], :limit => 50 )
------------
Everything loooks quite ok. I can login logout and I see how sessions
come and go. After 10 minutes the sessions are not shown as active.
MY QUESTIONS
1- How should I avoid duplicate sessions for users with an active
session? Where do I need to do the check? Any good example?
2- If I got it right I need to clean up the DB myself every now and
then. Is there anything else I need to clean up? Where is the stuff
stored at server? I''m using for development InstantRails in Windows but
I can''t find the created sessions anywhere.
Thanks again.
--
Posted via http://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---