rails runner ignored subdirectory RAILS_RELATIVE_URL_ROOT

850 views Asked by At

Using rails 4.2.0.beta4.

It looks like the env RAILS_RELATIVE_URL_ROOT is ignored when running scripts by runner. It works on my webserver when not using runner. But with runner I get this:

RAILS_RELATIVE_URL_ROOT=/somewhere ./bin/rails runner "puts Rails.application.routes.url_helpers.branches_path"
=> /branches # should be /somewhere/branches

The env is set correctly:

RAILS_RELATIVE_URL_ROOT=/somewhere ./bin/rails runner "puts ENV['RAILS_RELATIVE_URL_ROOT']"
=> /somewhere

I also tried to set it in the config with no luck:

config.action_controller.relative_url_root = '/somewhere'
config.relative_url_root = '/somewhere'

How can I make the runner respect the subdirectory/RAILS_RELATIVE_URL_ROOT?

For my webserver (unicorn btw) it works by starting it with the following config.ru (which is not used by runner afaik):

run Rack::URLMap.new(
      ENV['RAILS_RELATIVE_URL_ROOT'] => Rails.application
)
1

There are 1 answers

0
Markus On BEST ANSWER

It is a known rails bug and hopefully will be fixed soon: https://github.com/rails/rails/pull/17724