Last active
April 20, 2016 15:59
-
-
Save julianlconnor/0025511ebed3863d9feea13d63159348 to your computer and use it in GitHub Desktop.
Heroku, CloudFlare, Devise, Trackable
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
# NOTE: need to override Devise's Trackable `update_tracked_fields` when using CloudFlare & Heroku. | |
def update_tracked_fields(request) | |
super | |
# NOTE: need to pull the first IP out of a list of IPs since Heroku | |
# will append CloudFlare's IP. | |
old_current = self.current_sign_in_ip | |
new_current = if request.headers["X-Forwarded-For"].present? | |
request.headers["X-Forwarded-For"][/[0-9\.]+/] | |
else | |
request.remote_ip | |
end | |
self.last_sign_in_ip = old_current || new_current | |
self.current_sign_in_ip = new_current | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment