Rails: Get Client IP address

ma11hew28 picture ma11hew28 · Dec 16, 2010 · Viewed 103k times · Source

In Rails, what's the best way to get the ip address of the client connecting to the server?

Here are two ways I've found:

request.remote_ip
request.env['HTTP_X_REAL_IP']

Answer

loosecannon picture loosecannon · Dec 16, 2010

I would just use the request.remote_ip that's simple and it works. Any reason you need another method?

See: Get real IP address in local Rails development environment for some other things you can do with client server ip's.