compass overwrites image_url from sass-rails #500

Closed
cairo140 opened this Issue Jul 31, 2011 · 18 comments

8 participants

@cairo140

I wanted to add compass to an existing Rails 3.1.0.rc5 app that I have. I added the gem to the Gemfile, and used Ken Collins' fix to get the asset pipeline to recognize the compass framework stylesheets.

However, in the process of doing so, compass seemed to overwrite the recently-introduced image_url helper from sass-rails, which would break the links to precompiled assets in the production environment (it would link to /assets/my.png?12345 rather than /assets/my-12345.png)

@scottdavis
Compass member

this is a known issue and chris is "working on it"

@spohlenz

If it's of any help, requiring compass before sass-rails seems to work around the issue for me.

@cairo140
@scottdavis
Compass member

the issue is that compass and sass-rails image_url helpers take different arguments. compass needs to be able to detect if sass-rails is loaded and alias the functions

@huerlisi

@spohlenz and how do you achieve compass being required before sass-rails? Switching lines in Gemfile didn't help, adding an initializer requiring them didn't work out, either.

@spohlenz

@huerlisi an initializer is probably to late in the boot process. Try putting the requires directly in config/application.rb.

@huerlisi

@spohlenz thanks, works now!

@johnnym

@huerlisi, can you explain what you did exactly? I added require 'compass' and require 'sass-rails' to config/application.rb, but it seems that image-url still isn't being overridden by sass-rails.

@huerlisi

@johnnym, just realizing that I had to play a bit with rake assets:clean and rake tmp:clear to get the stylesheet actually rebuilt.

@johnnym

Thanks! The cache was the problem. I would have expected it to have been rebuilt automatically since I changed all the asset-url's I was using to image-url, but clearing it worked.

@scottdavis
Compass member

Just to warn you all the above solution is not the correct one it may make it work but the compass and sass-rails helpers take different arguments so down the line once this is fixed you will have to refactor.

https://github.com/rails/sass-rails/blob/master/lib/sass/rails/helpers.rb#L13
https://github.com/chriseppstein/compass/blob/master/lib/compass/sass_extensions/functions/urls.rb#L51

@dfischer

Any updates on this issue?

@scottdavis
Compass member
@alanhogan

See also: #519. Probably the same issue, but none of the fixes in this thread have worked for me.

@cairo140

For the folks who need a fix "yesterday", I can still manage to get around the issue (in what I hope is a forwards-compatible way) by using an ERB stylesheet instead. So, I still have the old included stylesheet:

.fancy-list {
  li {
    &.linked {
      background-image: image-url('right-arrow.png');
    }
  }
}

But then, I've just added a line to "application.css.scss.erb" (rename if necessary):

.fancy-list li.linked {
  background-image: url(<%= image_path("right-arrow.png") %>);
}

In some future point when this gets fixed, I can remove the line from application.css or even just leave it as is and it should work.

@aaronchi

works more simply with

.fancy-list li.linked {
  background-image: url(image_path("right-arrow.png"));
}

only the image_url function seems to be affected

@scottdavis
Compass member

this should be fixed in the current alpha

@scottdavis scottdavis closed this Sep 2, 2011
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment