currently logged in user list

1,610 views
Skip to first unread message

robj

unread,
Apr 6, 2010, 9:55:02 PM4/6/10
to Devise
What is the best way to obtain a list of currently logged in users?

I considered something like

User.find(:all, :conditions => ["current_sign_in_ip != '' "])

but current_sign_in_ip retains a value even after the user is logged
out

Thanks,
Rob

José Valim

unread,
Apr 7, 2010, 3:38:59 AM4/7/10
to plataforma...@googlegroups.com
You have to store a "last_request_at" in the database and get all users where the last_request_at was in the last 5 or 10 minutes. There is no way to tell for sure.



--
To unsubscribe, reply using "remove me" as the subject.



--
José Valim

Director of Engineering - Plataforma Tecnologia
Know more about us: http://plataformatec.com.br/en/

robj

unread,
Apr 14, 2010, 11:49:51 PM4/14/10
to Devise
Thanks, Apologies im a bit of rails newbie, and my searches for info
on last_request_at tend to all be related to Authlogic.

I have added last_request_at (as date) to my User model, how do I
configure devise/warden to actually use/update the field?

Im using warden 0.9.7, devise 1.0.4

Thanks,
Rob

Claudemiro

unread,
Apr 22, 2010, 1:02:30 PM4/22/10
to Devise
class ApplicationController < ActionController::Base
before_filter :set_last_request_at

private

def set_last_request_at
current_user.update_attribute(:last_request_at, Time.now) if
user_signed_in?
end
end

This will update the column after every request.
Reply all
Reply to author
Forward
0 new messages