Last Updated: February 25, 2016
·
3.006K
· jalada

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'

1 Response
Add your response

Couldn't get this to work until I ran rm -rf tmp/cache before changing the RAILS_RELATIVE_URL_ROOT variable -- took me a while to find that as the cause. Maybe that will help someone else.

over 1 year ago ·