Created
March 12, 2014 20:54
-
-
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)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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