How can I get the current absolute URL in my Ruby on Rails view?
The request.request_uri
only returns the relative URL
if you want to be specific, meaning, you know the path you need:
link_to current_path(@resource, :only_path => false), current_path(@resource)
You could use url_for(only_path: false)
This works for Ruby on Rails 3.0 and should be supported by most versions of Ruby on Rails:
request.env['REQUEST_URI']
I needed the application URL but with the subdirectory. I used:
root_url(:only_path => false)
You can set a variable to URI.parse(current_url)
, I don't see this proposal here yet and it works for me.
you can use any one for rails 3.2:
request.original_url
or
request.env["HTTP_REFERER"]
or
request.env['REQUEST_URI']
I think it will work every where
"#{request.protocol}#{request.host}:#{request.port}#{request.fullpath}"