Configuring Rails 3.1 and Compass Sprite_load_path

By default compass sprites are put in to the app/assets/images directory which is copied to public/assets on precompile/deploy. By moving the files to their own sprite folder only the generated images get moved in to public/assets when deploying to production which should save some file space.

Instructions

First create the directory app/assets/sprites

Then create the initializer below in config/initilaizers/sprite_load_path.rb:

Compass.add_configuration({:sprite_load_path => Compass.configuration.sprite_load_path + [Rails.root.join('app', 'assets', 'sprites')]}, 'sprites')

Caveats

This will not work with the stand alone compass command line since it will require rails to load in order to configure compass if you are using a compass.rb you can set the sprite_load_path like so:

sprite_load_path = Compass.configuration.sprite_load_path + [Rails.root.join('app', 'assets', 'sprites']

Comments