1

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?

3
  • What do you have in your compass config.rb for http_generated_images_path? I had a similar issue and it was resolved by setting the http config paths.
    – maxbeatty
    Mar 30, 2012 at 5:08
  • I don't see that config at all, and that's not related to this path problem. But thanks for letting me know, as I think it is a good thing to set, so the genereated file can reside outside the asset directory (which annoys for me).
    – lulalala
    Mar 30, 2012 at 12:48
  • 2
    I agree. Moving the generated sprite sheet outside app/assets means I don't have to try to exclude those files from version control. Don't forget to add the new path to rails assets paths. generated_images_dir = "tmp/sass-cache/sprites" in config/compass.rb. config.assets.paths += "tmp/sass-cache/sprites" in config/application.rb`. Mar 30, 2012 at 17:19

1 Answer 1

5

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"

1
  • thanks, the relative path is from the designer using Middleman. Will remember to convert this part next time. Note that compass-rails and compass 0.12.alpha.4 are interchangeable.
    – lulalala
    Mar 30, 2012 at 12:45

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.