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 :
According to documentation, you can use
request.host
orrequest.host_with_port
if you also need the portYou 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