Newbie q: capture IP address?

Is there a quick way to capture the IP address of the visiting user in
rails? Is it specific to the web server?

request.env[“REMOTE_ADDR”]

<%=request.inspect%> will show you some other information that you may
be
interested in accessing.

Vince W. wrote:

Is there a quick way to capture the IP address of the visiting user in
rails? Is it specific to the web server?

Use request.remote_ip in your controller.

Internally, this checks the environment variables HTTP_CLIENT_IP,
HTTP_X_FORWARDED_FOR and REMOTE_ADDR, so it should work for most server
setups.

Chris

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs