How to Get Current Host Url in Rails
You are in right place if you want to get root url along with port number in rails.
Code that works
This can be achieved by either root_url
or request.env[HTTP_HOST]
.
Use Case
In applications you may need to generate url that will link back to your application while sending email.
Problems it has solved:
Previously, we used to have environment variable like HOST: localhost:3000
saved in application.yml
which would be later called by ENV['HOST']
.
Leave a comment