Search code examples
ruby-on-railsbase-url

Get Rails base URL if not in controller


In controller a base URL could be got using request object, but my process is a worker thread started from initializer, and it doesn't have access to request.


Solution

  • If you don't have a request (which you don't, in the context of a background worker), then you can't tell the URL automatically and the only way is to set it explicitly. You could set it as an environment variable, or set it as a constant in an initializer, and then get it from there.