Rails app in a subdirectory

For Rails 4/5, you can set this in application.rb or production.rb:

config.relative_url_root = "/app1"

Or simply set this environment variable:

RAILS_RELATIVE_URL_ROOT='/app1'

However, I’ve found that this only prefixes paths to assets. URL paths created by url helpers doesn’t respect this setting.

Turns out, there’s a bug related to this: https://github.com/rails/rails/issues/5122

This is supposed to have fixed it, but I’ve not found that to be the case:
https://github.com/rails/rails/pull/18775/files

The documentation for this feature isn’t very clear on how exactly it’s supposed to work:

http://edgeguides.rubyonrails.org/configuring.html#deploy-to-a-subdirectory-relative-url-root

Maybe try namespacing instead:
http://guides.rubyonrails.org/routing.html#controller-namespaces-and-routing

This answer might also be helpful:
Configuring a Rails 4 app for production in a subdirectory under Apache

Leave a Comment