Skip to content

relative_url_root not respected #42243

@arianf

Description

@arianf

The docs here say config.action_controller.relative_url_root, which contradicts the docs once you follow that link
Screen Shot 2021-05-17 at 2 32 50 PM

This one says, config.relative_url_root
https://guides.rubyonrails.org/configuring.html#deploy-to-a-subdirectory-relative-url-root
Screen Shot 2021-05-17 at 2 34 08 PM

So which doc is correct? hmmm is it config.relative_url_root or config.action_controller.relative_url_root?

But who cares, lets say you set both of these in the config/environment/development.rb :

  config.relative_url_root = '/sub'
  config.action_controller.relative_url_root = '/sub'

then you run puma without setting the ENV['RAILS_RELATIVE_URL_ROOT']...

$ puma
(byebug) MyApp::Application.config.relative_url_root
"/sub"

(byebug) MyApp::Application.config.action_controller.relative_url_root
"/sub"

(byebug) MyApp::Application.routes.url_helpers.projects_url
"http://localhost/projects"

(byebug) MyApp::Application.routes.url_helpers.projects_path
"/projects"

So you can see above it doesn't work... now if I add in RAILS_RELATIVE_URL_ROOT="/sub" puma

$ RAILS_RELATIVE_URL_ROOT="/sub" puma

(byebug) MyApp::Application.routes.url_helpers.projects_url
"http://localhost/sub/projects"

(byebug) MyApp::Application.routes.url_helpers.projects_path
"/sub/projects"

You can see you are required to put the value into ENV. The docs seem to be incorrect. See issue: #24393 and #22074

I think it likely has to do with this:

Railties only look at the ENV variable and it doesn't follow the docs at all and it doesn't bother to check the value at config.relative_url_root or config.action_controller.relative_url_root

@relative_url_root = ENV["RAILS_RELATIVE_URL_ROOT"]

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions