views:

628

answers:

4

In a project I am working on, Apache is set up to only forward requests that come in as /prefix/* to mongrel. How can I tell ruby on rails to generate all URLs with that prefix?

I have the routes set up for forward to the correct controller action by doing this:

map.connect 'sfc/:controller/:action'

but that doesn't seem to affect the way that the url writer generates the URLs.

Any ideas?

+2  A: 

The RAILS_RELATIVE_URL_ROOT environment variable should do the trick, though I haven't tried it myself.

Can Berk Güder
+1  A: 

What about using the :path_prefix option:

map.connect ':controller/:action', :path_prefix => 'sfc'
Mike Breen
+2  A: 

You probably have another route (probably one of the default routes at the bottom of routes.rb) that URL generation is using in preference to the sfc-prefixed match. For example, if you have

map.connect "sfc/:controller/:action"
map.connect ":controller/:action/:id"

then url_for(:controller => 'x', :action => 'y', :id => 3) will return "/x/y/3". If you change it to

map.connect "sfc/:controller/:action"
map.connect "sfc/:controller/:action/:id"

you should get "/sfc/x/y/3".

Matt Burke
+1  A: 

Mongrel accepts a --prefix option that will then be prepended to all generated URLs. This is the only way I know of to be able to run multiple instances of the same application on one server.

Kyle Boon
Rails 2.3+ changes broke the --prefix option in mongrel and it has not been updated. You will have to monkey patch the code yourself to get it to work properly.
Corban Brook