Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails and Authlogic. Show currently logged in users

I would like to have the list of currently logged in users.

This code doesn't work :

<% UserSession.all.each do |user_session| %>

<% end %>
like image 619
manusvs650 Avatar asked Jan 21 '23 11:01

manusvs650


1 Answers

@syed-aslam has a good solution, but you could just let Authlogic do the work. Check out the module Authlogic::ActsAsAuthentic::LoggedInStatus which defines two scopes: logged_in, logged_out

Your code becomes:

<% User.logged_in.each do |user| %>

<% end %>

P.S. I would normally link to the RDoc instead of source code, but the RDoc seems to have problems at the moment.

like image 88
Anson Avatar answered Jan 28 '23 02:01

Anson