Display realtime list of logged in users ( Maybe using AuthLogic)

China☆狼群 提交于 2019-12-11 07:02:02

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!