Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I obtain user's last active time when using Devise?

Suppose Users are spending long time in the web-site.
How can I obtain user's last active time. Last active time means the last timestamp of user who requested(accessed to the page. user even doesn't need to update or create new record) to app.

A User might have signed in about an hour ago. Then he's still web surfing in my web site. I want the time of last request the user sent.

Is it possible?

Devise has current_sign_in_at but not last active time.

like image 267
cat Avatar asked Jan 02 '13 23:01

cat


1 Answers

The way I would implement this is to add a last_active_at datetime column to the User model, then putting something in my controller:

class ApplicationController
  before_filter :record_user_activity

  private

  def record_user_activity
    if current_user
      current_user.touch :last_active_at
    end
  end
end
like image 86
mesozoic Avatar answered Nov 05 '22 14:11

mesozoic