Reputation: 67
I am building a site in ruby on rails on a heroku server to deliver content to a user based on their location. I am using ipinfo_io to pull a user's ip and location via request.env['ipinfo'].ip
& request.env['ipinfo'].loc
I am then geocoding the request.env['ipinfo'].loc
via the ruby geocoder gem. I am using google api to geocode location.
This is all working fine. Where I am having an issue is when I pull the ip address. Viewing the logs and testing on my home devices, the GET request is done on a different IP address than what my home device is.
My home device ip will be 136.xx.xx.xxx and the GET request ip will be 198.xx.xx.xxx which is no where near where I currently am. How do I set up my environment to pull in the correct IP?
I have put the logs below with my correct ip and the GET ip:
info method=GET path="/favicon.ico" host=www.example.com fwd="136.xx.xx.xxx,172.xx.xx.xx" dyno=web.1 connect=1ms service=8ms status=200 bytes=143 protocol=https
INFO -- : Started GET "/" for 198.xx.xx.xx at 2021-04-07 17:49:01 +0000
Rails version 6.0.3.4 ruby version 2.6.3
Upvotes: 0
Views: 256
Reputation: 23
Have you tried with request.remote_ip ?
https://apidock.com/rails/ActionDispatch/Request/remote_ip
Upvotes: 1