Deploying Rails 3 apps to a subdirectory with the asset pipeline

When precompiling assets on deployment Rails has no idea where your application is hosted. If you are running your application on a subdirectory all of your image-url directives in your CSS for asset images will construct incorrect URLs.

The solution is to set the RAILS_RELATIVE_URL_ROOT environment variable when precompiling assets (either on the server or locally if you are checking in assets to Git).

For Capistrano this means adding the following line to your deploy.rb file:

default_environment['RAILS_RELATIVE_URL_ROOT'] = '/my-app'
This entry was posted in Blog, Ruby. Bookmark the permalink.