Search code examples
ruby-on-railsasset-pipelinecompass-sass

Rail + Compass sprite generation gives wrong image path


In my Rails 3.2.1 application I am using compass(0.12.alpha.4) to create sprites:

@import compass

@import "../images/category-icons/type/*.png"
@include all-type-sprites
//+all-type-sprites

The sprite image was genereated correctly, sitting in app/assets/images/category-icons/type-sa69c4767de.png

However the stylesheet generated is wrong. It points to /assets/../images/category-icons/type-sa69c4767de.png. It merely appends assets to the path. It works outside of Rails, so I think it has something to do with asset pipeline. What should I configure for this to work properly?


Solution

  • Are you using compass-rails? It ensures proper integration with the asset pipeline.

    Since Compass v0.12, this adapter is the only way to install compass into your rails application.

    Don't use a relative path to the source images. Image path references already search through the asset load path. Rails is configured to include app/assets/images in the asset load path by default.

    Change the import to:

    @import "category-icons/type/*.png"