code-quality

How to Get Current Host Url in Rails

how to get root url along with port number in rails

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

About the author

Prakash Poudel Sharma

Engineering Manager · Product Owner · Varicon

Engineering Manager at Varicon, leading the Onboarding squad as Product Owner. Eleven years of building software — first as a programmer, then as a founder, now sharpening the product craft from the inside of a focused team.

Keep reading

More on this

Join the conversation0 comments

What did you take away?

Thoughts, pushback, or a story of your own? Drop a reply below — I read every one.

Comments are powered by Disqus. By posting you agree to theirterms.

0:000:00