rails: getting ip address from request

This is useful if you want to log the ip address of the person using your rails app (except when the person is behind a proxy, thanks James!):
request.env['REMOTE_ADDR']
Taken from this ruby thread.


3 Responses to “rails: getting ip address from request”

  • James Says:

    Is this true when using a proxy?

  • Ben Says:

    You’re right, this won’t work so well when then client is behind a proxy.

  • James Says:

    However: I’m fairly sure (but too lazy to look it up) that there are ways (or there is *a* way) to have Mongrel pass this info along, possibly in an x-header field.

    Anyway, the main point is that people using a Web app behind a proxy need to be sure the proxy is telling the truth when inspecting headers and ENV values.

Leave a Reply