问题
I need to display a real-time or at least near real-time list of users currently logged into my site.
I'm using the AuthLogic gem to manage Registration/Login & Session management. Is there a quick way for me to find a list of current usernames logged into the site using authlogic?
I ask this new question because there seems to be conflicting answers on whether this is possible:
Rails and Authlogic. Show currently logged in users
How to get a list of online users in Authlogic?
Thanks
回答1:
Ok, I just tried it out there and the following code allows you access to all logged in users and their model attributes.
def online_users
return Member.logged_in
end
@loggedIn = online_users
@loggedIn.each do |member|
print member.username
print member.email
end
You must add the 'last_request_at' authlogic column to your user table.
回答2:
We can list the list of online users with my rails application by use of active record session store, please see this github app https://github.com/mohanraj-ramanujam/online-users
来源:https://stackoverflow.com/questions/5254857/display-realtime-list-of-logged-in-users-maybe-using-authlogic