Devise + Switch User : How to avoid update in trackable devise columns for a switch user?

I am using switch_user rails
to login as any other devise user from an admin account. When I use
switch_user for an account, the devise session updates all the devise
trackable attributes for that user such as:

t.integer “sign_in_count”,
t.datetime “current_sign_in_at”
t.datetime “last_sign_in_at”
t.string “current_sign_in_ip”
t.string “last_sign_in_ip”

which I don’t want to happen. These updates should happen only when an
user actually logs in and not for an admin account through switch_user.

How can I achieve this?



There is a way provided by devise gem to skip the Trackable fields
for a specific request. Devise uses a condition as :

if record.respond_to?(:update_tracked_fields!) &&
warden.authenticated?(options[:scope]) &&

Above condition can be found at

In whichever request you want to skip the Trackable fields updates you
need to set an variable devise.skip_trackable from environment as :

prepend_before_filter { env[“devise.skip_trackable”] = true }

This will skip the updating of following columns:

  1. sign_in_count
  2. current_sign_in_at
  3. last_sign_in_at
  4. current_sign_in_ip
  5. last_sign_in_ip

Please refer more

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs