Skip to content

Instantly share code, notes, and snippets.

@julianlconnor
Last active April 20, 2016 15:59
Show Gist options
  • Save julianlconnor/0025511ebed3863d9feea13d63159348 to your computer and use it in GitHub Desktop.
Save julianlconnor/0025511ebed3863d9feea13d63159348 to your computer and use it in GitHub Desktop.
Heroku, CloudFlare, Devise, Trackable
# 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