Reputation: 89333
What's the difference between request.env['REQUEST_URI'] and request.env['REQUEST_PATH'] in Rails? They always seem to contain the same value.
Upvotes: 19
Views: 19797
Reputation: 5056
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 ActionDispatch::Request to see other helpful methods.
Upvotes: 31
Reputation: 10890
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/
Upvotes: 12