Home > Mobile >  How to fetch base URL in rails?
How to fetch base URL in rails?

Time:02-19

I need the base url of my rails app in its code. Example if my site is www.abc.com then i want this to be accessible in all controllers. Is there any method to get it?

CodePudding user response:

There are two step to archive :

  1. According to documentation, you can use request.host or request.host_with_port if you also need the port

  2. You can use environment variable to store your BASE_URL, so that when you need to get your base url, you can call it like ENV['BASE_URL'] either in the model, controller or view

You can use figaro gem to help you manage your environment variable

  • Related