RE: URLs in IIS - Please look at my code and offersuggestion

Jeremy: as I said on

http://dev.rubyonrails.com/ticket/2602

“If I have a “project” controller and a “show” action, why does Rails
“link_to” insist on doing “/project/foo” which will go to the root of a
webserver? The reason is that Rails is assuming that the app is mounted
to the base of a server and it’s easier to do that than to figure out
how the relative paths would work.”

IIS / Apache + SCGI have this need ONLY if the app is run in a subfolder
(i.e… NOT the root of the webserver or vhost).

Rails currently (unless you symlink - again, a hack) assumes that you’ll
run your app in a vhost configuration. That might work for intranets,
but I might want to do this

www.uwec.edu/biology/coolapp

Instead of

coolapp.uwec.edu

Currently, /biology/coolapp needs to be prepended to all of the URLs
that are generated from Rails, including javascripts. Css files, images,
redirect_to, link_to, etc… Rewrite rules get you TO the site but for
some reason it stops working after that.

I don’t know why IIS and SCGI have this need.

Probably because 1. SCGI serves the apps outside of apache so
AbsractRequest#relative_url_root returns null in that case, and the
same with IIS.

But that’s not the heart of the question really… I need to fix this
but I need to know if what I’m doing is the appropriate way to fix the
problem. I’m looking for guidance on whether this is the appropriate
method and class to be overriding, and if I’m overriding it in the wrong
way (should this be a plugin insteead?)

As also suggested on Peak Obsession

"If you write a plugin or patch that teaches [the request instance] how
to get this information from your setup, or just redefines that method
to return the prefix you expect, then you should be set.

Adding a straight config value for this would not be too hard either…
however it might be nice to have a solution that automatically
determines the correct prefix. "

So that’s what I’m looking for feedback on. I see that my ticket has
been reopened, but for my own curiosity, I’d like to know what you and
others feel would be the best place to tackle this? (even if it doesn’t
get fixed in the rails core, how would I best fix it for my setup so I
can share it with others?)

Thanks for your reply. I appreciate any help.

I did this by using the routes.rb config to prefix the base uri for all
of the requests. This also fixes quite a few other problems with
redirect_to and render as well.

Remember, the routes system goes in two directions:

  • /stuff/dome —> StuffController.dome
    redirect_to :controller => “stuff”, :action => “dome” —> /stuff/dome

So if you setup your routes to require a prefix then it should
generate the prefix on the redirect_to call.

Zed A. Shaw

On Fri, 11 Nov 2005 15:55:03 -0600