You should use request.original_url to get the current URL.
This method is documented at original_url method, but if you're curious, the implementation is:
def original_url
base_url + original_fullpath
end
For Rails 3:
You can write "#{request.protocol}#{request.host_with_port}#{request.fullpath}", since request.url is now deprecated.
For Rails 2:
You can write request.url instead of request.request_uri. This combines the protocol (usually http://) with the host, and request_uri to give you the full address.
This works for Ruby on Rails 3.0 and should be supported by most versions of Ruby on Rails:
And you can easily add some new parameter:
To get the absolute URL which means that the
from the root
it can be displayed like thisThe users_url helper generates a URL that includes the protocol and host name. The users_path helper generates only the path portion.
For Rails 3.2 or Rails 4+
You should use
request.original_url
to get the current URL.This method is documented at original_url method, but if you're curious, the implementation is:
For Rails 3:
You can write
"#{request.protocol}#{request.host_with_port}#{request.fullpath}"
, sincerequest.url
is now deprecated.For Rails 2:
You can write
request.url
instead ofrequest.request_uri
. This combines the protocol (usually http://) with the host, and request_uri to give you the full address.To get the request URL without any query parameters.
You can set a variable to
URI.parse(current_url)
, I don't see this proposal here yet and it works for me.