Majoris
Majoris

Reputation: 3189

Ruby rails - list active sessions

Is there any way to get the list of all active sessions in rails? I have memory cached session list, and I want to view the user ids, source ip, time stamp, duration etc. for basic administration purposes.

Upvotes: 4

Views: 2101

Answers (1)

Sean
Sean

Reputation: 2891

To expand on my comment, I am doing something similar to what you want to do. I am using authlogic but I imagine that you can do something equivalent with other authentication packages.

I am using authlogic's auto logout capabilities and have it set to log people out after 120 minutes. Knowing that, generating a list is simple. I just do the following:

<% User.find(:all, :conditions => ["last_request_at > ?", 120.minutes.ago]).each do |user| %>
  <li>
    <%= link_to user.name, admin_person_path(user.bio) %>
    (<%= mail_to user.email %>) <%= time_ago_in_words(user.last_request_at) %> ago
  </li>
<% end %>

You can see that I just list their names, e-mails, and when they last made a request. It would be trivial to add last_login_ip, current_login_at, etc.

Hope this helps.

Upvotes: 2

Related Questions