Get real IP address in local Rails development environment -


i have rails 2.3.8, ruby 1.8.7, mongrel web server , mysql database.

i in development mode , need find real ip address

when use request.remote_ip getting ip 127.0.0.1

i know getting 127.0.0.1 because developing on local machine.. there way real ip-address if on local machine?

i using these mentioned below in controller , 127.0.0.1 of them in view.

request.remote_ip request.env["http_x_forwarded_for"] request.remote_addr request.env['remote_addr'] 

as far can see there no standard method getting remote address of local machine. if need remote address (testing) geocoding, suggest adding 127.0.0.1 database table matches ip addresses locations.

as last resort hard code remote address. e.g. this:

class applicationcontroller < actioncontroller::base   def remote_ip     if request.remote_ip == '127.0.0.1'       # hard coded remote address       '123.45.67.89'     else       request.remote_ip     end   end end  class mycontroller < applicationcontroller   def index     @client_ip = remote_ip()   end end 

Comments

Popular posts from this blog

ASP.NET/SQL find the element ID and update database -

jquery - appear modal windows bottom -

c++ - Compiling static TagLib 1.6.3 libraries for Windows -