What's the difference between request.env['REQUEST_URI'] and request.env['REQUEST_PATH'] in Rails? They always seem to contain the same value.
views:
1089answers:
2
+2
A:
I believe REQUEST_URI
also contains query GET arguments, whereas REQUEST_PATH
don't. But I'm not completely sure of that.
For example :
REQUEST_URI = /foo/bar/?x=1&y=2
REQUEST_PATH = /foo/bar/
Pierre Bourdon
2009-10-03 23:21:48
+4
A:
I believe delroth is correct about the distinction, however in almost all cases it's better to use the methods in Request instead of directly accessing the environment variables.
request.request_uri returns the requested url including the query string and without the domain.
request.path returns the path of the request without the query string, domain and any relative root (if your app runs from a directory other than root).
See the Rails API for ActionController::Request to see other helpful methods.
Peter Wagenet
2009-10-04 01:10:44