This devise extension, will ensure that devise will update a flag/timestamp on the model whenever a user is set. With this kind of feature you could show in your views something like last seen 3 weeks ago or last seen 2 minutes ago.
You know, add this line to your application's Gemfile:
gem 'devise_last_seen'
And then execute:
$ bundle
In your model, add :lastseenable
module as such:
# app/models/user.rb
class User < ApplicationRecord
devise :database_authenticable, ..., :lastseenable
end
Generate a rails migration to add the column to your devise model:
bundle exec rails g migration add_last_seen_to_users last_seen:datetime
class AddLastSeenToUsers < ActiveRecord::Migration[6.1]
def change
add_column :users, :last_seen, :datetime
end
end
Besides the column requirement you don't need customizations, but if you want to...
# config/initializers/devise.rb
Devise.setup do |config|
...
# Interval (in seconds) to update the :last_seen_at_attribute attr
# config.last_seen_at_interval = 5.minutes
# Attribute who will be updated every time a user is set by the Warden's after_save callback
# Remember to check if this column name is present on the devise model table.
# config.last_seen_at_attribute = :last_seen
end
After checking out the repo, run bin/setup
to install dependencies. Then, run bundle exec rspec
to run the tests.
To install this gem onto your local machine, run bundle exec rake install
.
To release a new version, update the version number in version.rb
, and then run bundle exec rake release
, which will create a git tag for the version, push git commits and tags, and push the .gem
file to rubygems.org.
Bug reports and pull requests are welcome on GitHub at https://github.com/brunoocasali/devise_last_seen. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.
The gem is available as open source under the terms of the MIT License.
Everyone interacting in the devise_last_seen
project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.
This gem only could be done with help of other gems like:
- @shenoudab devise_traceable
- @devise-security devise-security
- @heartcombo devise
- @ctide devise_lastseenable
- @iplan iplan-devise-lastseenable