This project is archived and is in readonly mode.

#6542 new
Thomas Fritzsche

Rails is not a Rack Application (SCRIPT_NAME vs. relative_url_root ?)

Reported by Thomas Fritzsche | March 7th, 2011 @ 10:43 PM

Hello Rails-Hackers,

I'm just in process creating some rack-middleware where I try to adjust env["SCRIPT_NAME"] before Rails get's called in order to influence the way links are generated.
SCRIPT_NAME is defined by Rack as:
"SCRIPT_NAME: The initial portion of the request URL’s “path” that corresponds to the application object, so that the application knows its virtual “location”. This may be an empty string, if the application corresponds to the “root” of the server."

So if my app is in www.host.com/my_rails_webapp/ SCRIPT_SERVER it's "/my_rails_webapp".

I assume if I overwrite this value in my rack middleware than rails should respect this during link-generation.
However this does not work for me as I expected. I'm just hobby rails programer so by Rails debugging scrills are limited, but it looks like Rails is not using SCRIPT_NAME, but instead is using "config.relative_url_root" in Application Controller's.

I try to make a sense out of the rails source greb'ing after string SCRIPT_NAME, but I just come up with actionpack/lib/action_controller/metal/compatibility.rb that has:


  # ROUTES TODO: This should be handled by a middleware and route generation
  # should be able to handle SCRIPT_NAME
  self.config.relative_url_root = ENV['RAILS_RELATIVE_URL_ROOT']

Well.... I can just agree with the author: I think this should use SCRIPT_NAME. Sorry when my rails's skills are not good enough to provide a patch for this TODO or if I have overlooked something.

Thanks a lot!
Thomas

No comments found

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>

People watching this ticket

Pages