When generating sprites with Compass (which is extremely easy), we found that the default output directory for your sprites is the same as the root images directory. This is annoying because we would have to add a line line
app/assets/images/icons-*.png to our
.gitignore, repeated for each sprite file.
We wanted to put all our sprites in a single folder to be put in
.gitignore — this was easy to find, by adding
config.compass.generated_images_dir = 'public/sprites' to our
config/application.rb. The next problem was that while the sprite file was correctly being saved to e.g.
public/sprites/icons-xxx.png, the client-facing path to the sprite file was still
/assets/icons-xxx.png which was always 404ing.
The final answer came from an open pull request on compass-rails which clearly explains that you need to add the output path to the assets path, e.g.
config.assets.paths << Rails.root.join('public', 'sprites'). Finally, we can easily add
public/sprites to our
The other gotcha we encountered today is that compass-rails only regenerates the sprite file when the sprites CSS file changes, not when you add or remove files from the globbed path.
About the Author