I have Rails 2.3.8, Ruby 1.8.7, Mongrel Web Server and MySQL database.
I am in the development mode and I need to find the real IP address
If you access the development machine with your real IP you should get your real IP, so don't use localhost, but your use your real IP. Not all routers are will allow LAN access to a machine to an external IP address that is actually on that LAN, but most will.
Problem:
We were trying to do a similar thing for a project recently and were having trouble using request.remote_ip
in our code. It kept returning 127.0.0.1
or ::1
. When combined with the Geocoder gem it was giving us an empty array and was basically useless.
Solution:
There's a really nice API at telize.com which returns the IP address of whatever hits it. The code we implemented looked something like this:
location = Geocoder.search(HTTParty.get('http://www.telize.com/ip').body)
It's not the most rails-y way to do it, but I think this is a pretty good solution since it will work locally and on production as well. The only potential problem is if you hit their API limit, but for small projects this should be a non-issue.