compass-rails: Incorrect path generated for sprites

We’ve had an intermittent problem with a Rails 4.0.3 app using compass-rails 1.1.7, compass 0.12.2 and sass-rails 4.0.3 (the problem also occurred on previous versions of rails and all these gems, these just happen to be what we’re using now).

Essentially what happens is that during Sass compilation and sprite generation with compass, some of the image URLs generated are incorrect. For example, given a folder of images in

app/assets/images/application/header

and the following sprite map

  $header_sprites: sprite-map(
  "application/header/*.png",
  $spacing: 3px,
  $header-background-repeat: repeat-x,
  $header-level_progress_bar_middle-repeat: repeat-x,
  $header-section_header-repeat: repeat-x);

and an SCSS property that uses that sprite map:

        background: sprite($application_sprites, 'best_week', 0, 4px);

the correct generated CSS property should have the image URL

/assets/application/header-s9d32d78026.png

However, with no apparent pattern, occasionally the URL will be generated incorrectly as

/application/header-s9d32d78026.png

Note the missing “/assets” at the beginning of the URL. Note that the sprite image is correctly generated and is at the correct path on the filesystem and can be loaded from the correct URL.

It’s not all the time, and it’s not every sprite. We have a number of sprite files in our application and it seems to consistently happen to only 3 of these sprite files. This happens in both the development and test environments; we’ve never seen a problem in production. This problem routinely causes our test suite to fail.

Reproducing the problem in a consistent way has been difficult. Sometimes simply reordering the “require” lines in app/assets/stylesheets/application.css will cause the problem to go away. When the lines are put back in the original, failing order, sometimes the problem is still fixed, other times not. Clearing the temp cache (rake tmp:clear) and cleaning assets (rake assets:clean) seems to have no effect.

I understand this is a bit vague and I apologize for that. I’ve tried to boil it down to a simple test case but I haven’t been able to. Having lost numerous days worth of time on this over the past several months, I’m hoping someone else has seen this, or might have some insight into what might be happening.

About this issue

  • Original URL
  • State: closed
  • Created 10 years ago
  • Comments: 22 (4 by maintainers)

Most upvoted comments

After playing around more, I was able to resolve this by adding to assets.paths. Sorry for the disruption. My complete compass.rb file is now:

Rails.application.configure do
    sprite_dir = File.join(config.compass.generated_images_dir, 'generated')
    config.compass.generated_images_dir = sprite_dir
    config.assets.paths << sprite_dir
end