Skip to content

Deploying a rails app on a suburi

by Topper on February 7th, 2009

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”
[/ruby]

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”
[/ruby]

If you care – my virtual host looks something like:
[code]

ServerName localhost
DocumentRoot /Library/WebServer/Documents
RailsBaseURI /rails


[/code]

From → Social Web

  • José Ignacio

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

  • 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.

  • Pat Murray

    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!

  • emc lab

    Hi, is the solution only good for rails 2.x? We are deploying 2nd rails 3.2.12 app to a server with sub uri nbhy and could not make it work completely. We created a constant keeping the value of ‘nbhy’ and use it as prefix for routes. But something drives us crazy is that sometime the ‘nbhy’ is carrier over and another time it is not. We are kind of run out of ideas….