Add a new asset path in Rails 3.1

Andrew picture Andrew · Jun 28, 2011 · Viewed 41.4k times · Source

Does anyone know how to add another folder to the asset pipeline in Rails 3.1?

I'd like to serve app/assets/fonts the same way app/assets/images is served.


Update: 5-7-2013

Just to add some clarification for future people who find this question to explicitly add an asset path, in your application.rb file:

config.assets.paths << "#{Rails.root}/app/assets/fonts"

However, since the above path is under app/assets you don't have to add it explicitly, you just need to restart your rails app so Sprockets can pick it up.

You will have to explicitly add paths that are outside of app/assets,lib/assets, or vendor/assets, and just remember that while Sprockets picks up new files in folders that were present when your application loaded, in my experience it does not pick up new folders in the asset paths without a restart.

Answer

Jason L Perry picture Jason L Perry · Jun 28, 2011

Andrew, app/assets/fonts is actually already in your asset load path, along with images. So you can just point to the asset in the same way: <%= asset_path('/Ubuntu/Ubuntu-R-webfont.eot') %>[1] or how ever you are referencing your images.

It took me a while to wrap my head around this as well. I still don't know what happens if there's a file with the same name in app/assets/fonts and app/assets/images.

[1] Assuming you have a font at app/assets/fonts/Ubuntu/Ubuntu-R-webfont.eot