The URL returned by request.url ignores the value of Rails.config.action_controller.relative_url_root.
The documentation of ActionDisplay::HTTP:URL#url says that it "Returns the complete URL used for this request". This is not true for projects that are not mounted under /.
This means that projects that use request.url cannot work unmodified when mounted under other directories with RAILS_RELATIVE_URL_ROOT.
Steps to reproduce
-
Create a minimal Rails application with the model "Foo".
-
In app/view/foo/index.html.erb write
request.url = <%= request.url %>
relative_url = <%= controller.relative_url_root %>
-
Setup Apache
RewriteRule ^/bar(.*)$ http://localhost:4000/$1 [P,L]
ProxyPassReverse /bar http://localhost:4000/
-
Launch the Rails application
RAILS_RELATIVE_URL_ROOT=/bar bundle exec bin/rails -p 4000
-
Visit http://localhost/bar/foo
Expected behavior
The page should display
request.url = http://localhost/bar/foo
relative_url = /bar
Actual behavior
The page displays
request.url = http://localhost/foo
relative_url = /bar
Please note the missing /bar in request.url.
System configuration
Rails version: 4.2.5
Ruby version: 2.2.3
The URL returned by
request.urlignores the value ofRails.config.action_controller.relative_url_root.The documentation of
ActionDisplay::HTTP:URL#urlsays that it "Returns the complete URL used for this request". This is not true for projects that are not mounted under/.This means that projects that use
request.urlcannot work unmodified when mounted under other directories withRAILS_RELATIVE_URL_ROOT.Steps to reproduce
Create a minimal Rails application with the model "Foo".
In
app/view/foo/index.html.erbwriteSetup Apache
Launch the Rails application
Visit
http://localhost/bar/fooExpected behavior
The page should display
Actual behavior
The page displays
Please note the missing
/barinrequest.url.System configuration
Rails version: 4.2.5
Ruby version: 2.2.3