I have a Rails 3 application and it's using Devise for the authentication.
I would like to display the date and time each user last logged in within the administration table of users.
I have based the application on the following application:
https://github.com/dannymcc/rails3-base
I have read through the Devise GitHub wiki and notice that it mentions that user events are trackable, but I can't find any information regarding accessing the information etc.
Any help/advice would be greatly appreciated!
Thanks,
Danny
Instead of
user.last_sign_in_at
usecurrent_user.sign_in_at
as you want the last sign in details of user logged in.The Devise documentation outlines the trackable module which will do what you want. In your user model, include the
:trackable
module like so:And make sure your database has the right fields. Not sure how do this if you already have a user table, but adding fields with the right names and types should do the trick. My migration to create my users table looks like so:
The
t.trackable
will add the correct fields. In my user model, they're as follows:Then you can just do
user.last_sign_in_at
and check the strftime documentation on how to output the time in the format you want.