How can I get current absolute URL in my Rails view?
The request.request_uri
gives me only relative URL.
How can I get current absolute URL in my Rails view?
The request.request_uri
gives me only relative URL.
When you say only relative, do you mean just without the domain?
If so, look into request.domain
You want 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.
I think request.domain would work, but what if you're in a sub directory like blah.blah.com? Something like this could work:
<%= request.env["HTTP_HOST"] + page = "/" + request.path_parameters['controller'] + "/" + request.path_parameters['action'] %>
Change the parameters based on your path structure.
Hope that helps!
This current_url method returns the current url and allows to merge in other params
current_url --> http://...
current_url(:page=>4) --> http://...&page=4