Skip to content

Instantly share code, notes, and snippets.

@lbalceda
Created March 12, 2014 20:54
Show Gist options
  • Save lbalceda/9516078 to your computer and use it in GitHub Desktop.
Save lbalceda/9516078 to your computer and use it in GitHub Desktop.
override Devise to not update trackable fields when switching from admin to a normal user (using switch_user ruby gem)
#include all in an override initializer
module Devise
module Models
module Trackable
alias_method :original_update_tracked_fields!, :update_tracked_fields!
def update_tracked_fields!(request)
original_update_tracked_fields!(request) unless request.env["devise.skip_trackable"]
end
end
end
end
SwitchUserController.class_eval do
def set_current_user
request.env["devise.skip_trackable"] = "true"
handle_request(params)
redirect_to(SwitchUser.redirect_path.call(request, params))
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment