Category :

Published on :Oct 30, 2015

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'].

Loading

Interested In Working Together ?

Over 8 years of industry experience in Game/Frontend
development with special interest.
Book your Consultation
© Prakash Poudel