If I'm in a URL such as
http://domain.com/mysite/bla
How can I request just the URL with no paths? Such as
http://domain.com
You should use request. original_url to get the current URL.
request.host
should do the trick, or:
request.port.blank? ? request.host : "#{request.host}: #{request.port}"
if you need to include the port too.
You can use this
<%= request.protocol + request.host_with_port %> #=> https://domain.com:3000 <%= request.protocol + request.host %> #=> https://domain.com
Starting from Rails 3.2 you can also use
<%= request.base_url %> #=> https://domain.com:3000
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With