Live to Code

code to live

Generating correct asset paths for a Rails app running under a sub-uri

13 Nov 2012 | , , ,

By default, when assets are precompiled, the paths are generated as absolute paths beginning with /assets.

If your application is running under a sub-uri and your asset path is being generated by Rails, you can make Rails include the sub-uri in the asset path by setting the following Capistrano variable to define the RAILS_RELATIVE_URL_ROOT.

Capistrano will include this in the assets:precompile task, which will ensure Rails generates the correct asset paths under /my-sub-uri/assets/.

set :asset_env, "RAILS_GROUPS=assets RAILS_RELATIVE_URL_ROOT='/my-sub-uri'"