How can I get the current absolute URL in my Ruby on Rails view?
The request.request_uri only returns the relative URL.
Sommaire |
How can I get the current absolute URL in my Ruby on Rails view?
The request.request_uri only returns the relative URL.
You should use request.original_url to get the current URL.
http://api.rubyonrails.org/classes/ActionDispatch/Request.html#method-i-original_url http://api.rubyonrails.org/classes/ActionDispatch/Request.html#method-i-original_url
def original_url base_url + original_fullpath end
You can write "#{request.protocol}#{request.host_with_port}#{request.fullpath}", since request.url is now deprecated.
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.
License : cc by-sa 3.0
http://stackoverflow.com/questions/2165665/how-do-i-get-the-current-absolute-url-in-ruby-on-rails