Deploying a rails app on a suburi

I followed the instructions at the phusion passenger site and couldn't exactly get my app to run in a suburi - it kept trying to use that suburi when looking up routes.

I had found this:

WRONG!

RUBY:
ActionController::AbstractRequest.relative_url_root = "/rails"

However, there was a deprecation warning - and it seemed not to work at all. I then stumbled upon this which seems to work:

RIGHT!

RUBY:
config.action_controller.relative_url_root = "/rails"

If you care - my virtual host looks something like:

CODE:
<virtualhost *:80>
   ServerName localhost
   DocumentRoot /Library/WebServer/Documents
   RailsBaseURI /rails

</virtualhost>

The Conversation {3 comments}

  1. José Ignacio {Tuesday March 24, 2009 @ 8:16 am}

    Unlike running Mongrel with –prefix, with your solution image URI’s in stylesheets will be broken. How to solve that?

  2. Topper {Tuesday March 24, 2009 @ 8:29 am}

    Well… then you’re using mongrel :-). Actually I was thinking about this problem yesterday. I don’t see a good way except using either your webserver (apache, nginx) or changing your stylesheets. You *could* do that at build time to keep ‘em independent while you’re developing.

  3. Pat Murray {Wednesday April 29, 2009 @ 7:00 pm}

    Thanks very much, this worked perfectly for me!

    I’m also running phusion passenger to deploy my site to a sub-uri.

    I already have one site running, and had fixed that one with a combination of statically prefixed routes, and adding the following to my production.rb to fix the stylesheet linking:
    ActionController::Base.asset_host = “http://xx.com/specs”

    With this solution, I still need to add that line. This seems to be a much better solution though, because if the site was moved to a different sub-uri, only two lines need to be changed!

Speak Your Peace

  • Comment Policy:Could go here if there's a nagging need Login Instructions: Would go here if there's a desire.