Ruby on Rails
HowtoDeployRailsAppUnderDirectory (Version #9)

WikiGardening in progress. We’re combining/reorganizing several related howto’s at the moment, apologies for the dust. Since Rails 0.10 includes Routes, that are meant to replace the use of mod_rewrite and provide more portability across web servers, much of this information is nolonger relevant; the remander is being moved under HowToSetTheBaseURLsOfYourRailsApps.

p{border:1px solid green;padding: 0.5em;}.If you’re using mongrel, you can use the prefix=/subdir in your mongrel startup script, and add ProxyPass /subdir http://localhost:3000/subdir to the Apache configurations.

Or: Howto Deploy a Rails App in a Subdirectory

There seems to be a number of gotchas for running a rails app under a directory i.e. http://www.blah.com/somename/

Please update with the best solutions for these problems. Specifically solutions that allow the directory to a deploy time decision i.e. configuration changes only. If you are using Apache and have access to httpd.conf, you may want to look at HowtoDeployMoreThanOneRailsAppOnOneMachine

1. URLs.

in config/routes.rb make sure you prefix all urls with your application path (e.g. somename).

map.connect 'somename/:controller/:action/:id'

hopefully this path can one day be automatically determined, or at least configured in a single place.

2. Static Content i.e. stylesheets and graphics.

Use url_for with a fake controller name, and extra param.

<%= url_for( :controller => "stylesheets", :file => "scaffold.css" ) %>

then in config/routes.rb

map.connect 'somename/stylesheets/:file', :controller => "stylesheets"

3. Asset Link Tags

Where a suitable one exists, Asset Tags are probably the best way of doing this. For example,

<%= stylesheet_link_tag “scaffold” %>

If the Asset Link Tags don’t recognise your subdirectory, you can add the following to your environment, eg config/environments/production.rb:


ActionController::Base.asset_host = ‘/somename’

WikiGardening in progress. We’re combining/reorganizing several related howto’s at the moment, apologies for the dust. Since Rails 0.10 includes Routes, that are meant to replace the use of mod_rewrite and provide more portability across web servers, much of this information is nolonger relevant; the remander is being moved under HowToSetTheBaseURLsOfYourRailsApps.

p{border:1px solid green;padding: 0.5em;}.If you’re using mongrel, you can use the prefix=/subdir in your mongrel startup script, and add ProxyPass /subdir http://localhost:3000/subdir to the Apache configurations.

Or: Howto Deploy a Rails App in a Subdirectory

There seems to be a number of gotchas for running a rails app under a directory i.e. http://www.blah.com/somename/

Please update with the best solutions for these problems. Specifically solutions that allow the directory to a deploy time decision i.e. configuration changes only. If you are using Apache and have access to httpd.conf, you may want to look at HowtoDeployMoreThanOneRailsAppOnOneMachine

1. URLs.

in config/routes.rb make sure you prefix all urls with your application path (e.g. somename).

map.connect 'somename/:controller/:action/:id'

hopefully this path can one day be automatically determined, or at least configured in a single place.

2. Static Content i.e. stylesheets and graphics.

Use url_for with a fake controller name, and extra param.

<%= url_for( :controller => "stylesheets", :file => "scaffold.css" ) %>

then in config/routes.rb

map.connect 'somename/stylesheets/:file', :controller => "stylesheets"

3. Asset Link Tags

Where a suitable one exists, Asset Tags are probably the best way of doing this. For example,

<%= stylesheet_link_tag “scaffold” %>

If the Asset Link Tags don’t recognise your subdirectory, you can add the following to your environment, eg config/environments/production.rb:


ActionController::Base.asset_host = ‘/somename’