You can add before_filter to your ApplicationController to set the current date / time in the last_request_at field in your users table, which you must first add through migration. In the method called from the before_filter file, you must make sure that the user is authenticated first, of course. And you may want, in addition to the filter, for actions that do not require authentication.
Then, assuming that you have included the Timeoutable module in the user model, you can find out if the user session is current or not by making this call:
user.timedout?(user.last_request_at)
Timedout method ? (last_access) defined in the Timeoutable module compares the development session timeout with the last request time / date.
As an additional note, you may need to update last_request_at if the last value of last_request_at is more than a minute ago (or any time interval you choose). Otherwise, if there are many controller calls on your page, for example mine, through AJAX, in one request there are many unnecessary db updates.
source share