Helper for asset pipeline "image-tag" renders /images instead of /assets urls #57

Closed
avocade opened this Issue Sep 26, 2011 · 32 comments
@avocade

Using latest sass-rails and rails from edge 5.minutes.ago:

gem 'rake', '0.8.7'
gem 'rails', :git => 'git://github.com/rails/rails.git', :branch=>'3-1-stable'

gem 'sprockets'
gem 'jquery-rails'

group :assets do
  gem 'sass-rails', :git => 'git://github.com/rails/sass-rails.git', :branch=>'3-1-stable'
  gem 'coffee-rails', '~> 3.1.0'
  gem 'uglifier'
  gem 'compass', '~> 0.12.alpha'
  gem 'compass-susy-plugin', :require => 'susy'  # http://susy.oddbird.net/tutorial/
  gem 'oily_png' # for faster compass sprite PNG compilation
end

With latest rails 3-1-stable commit by santiago, image_tag in erb views now works fine, renders /assets/ instead of /images again as in 3.1.0.

But "image-tag('image.png')" in sass and scss still returns /images/image.png instead of /assets/image.png.

@avocade

If this change is deliberate, then the docs should be updated to reflect:

As a convenience, for each of the following asset classes there are corresponding -path and -url helpers: image, font, video, audio, javascript, stylesheet. For example: image-url("rails.png") becomes url(/assets/rails.png) and image-path("rails.png") becomes "/assets/rails.png".
@scottdavis

something in your setup must be outdated im using these in a fresh 3.1 app and im getting the desired results try not using it from git

@avocade

Wasn't able to run the tests due to missing 3.2.0.beta gem on 'bundle install', but the following test specifies the correct expected result (/assets/rails.png) and should fail if run.

sass_rails_test.rb:

test "sass asset paths work" do
  css_output = sprockets_render("scss_project", "application.css.scss")
  assert_match css_output, %r{asset-path:\s*"/assets/rails.png"}, 'asset-path:\s*"/assets/rails.png"'
  assert_match css_output, %r{asset-url:\s*url\(/assets/rails.png\)}, 'asset-url:\s*url\(/assets/rails.png\)'
  assert_match css_output, %r{image-url:\s*url\(/assets/rails.png\)}, 'image-url:\s*url\(/assets/rails.png\)'

  asset_data_url_regexp = %r{asset-data-url:\s*url\((.*?)\)}
  assert_match css_output, asset_data_url_regexp, 'asset-data-url:\s*url\((.*?)\)'
  asset_data_url_match = css_output.match(asset_data_url_regexp)[1]
  asset_data_url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ElEPSJ4bXAuZGlkOkI3Njk0MTVBRDY2QzExRTA5RTMzQTlDQTZFODJBQTFCIi8%2BIDwvcmRmOkRlc2NyaXB0aW9uPiA8L3JkZjpSREY%2BIDwveDp4bXBtZXRhPiA8P3hwYWNrZXQgZW5kPSJyIj8%2B0HhJ9AAAABBJREFUeNpi%2BP%2F%2FPwNAgAEACPwC%2FtuiTRYAAAAASUVORK5CYII%3D"
  assert_equal asset_data_url_expected, asset_data_url_match
end
@avocade

According to jose, this was fixed as well in the latest commit to 3-1-stable, so closing this. Must still be using a slightly older commit.

@avocade avocade closed this Sep 26, 2011
@avocade

Wish I could specify a :commit => '64d7878bc8aacf236f3b4e36f0a07d5955a76230' in bundle, since latest commit doesn't have a special branch. Would be great to lock down on this until the next 3.1.x release.

@spastorino
Ruby on Rails member

@avocade use 3-1-stable branch the fix is there

@avocade

Using it, still get same issue. But it's obviously a caching issue somewhere (gem or sass), so no worries.

Much appreciated!

@guilleiguaran
Ruby on Rails member

Try with rake tmp:cache:clear

@avocade

First thing I tried :) Also cleared .sass-cache. And cleared the Chrome cache. Thanks for the suggestions, though!

@spastorino spastorino reopened this Sep 26, 2011
@chriseppstein

some sass-rails work is needed. More info: rails/rails#3126 (comment)

@sush

The image_tag helper is working fine with the specified commit but I encounter a very strange issue with image-url in my .scss files.
All my .scss files resolve image-url as url(/assets/..) except one which resolves url(/images/...) . (I have cleared the cache)

@avocade

Still getting the same bug as Sush here, cleared all caches (including browser), double-checking with curl but still getting same /image/image.png urls...

@gucki

I'm not sure if it's related, but I had a project not using require "rails/all" in application.rb. After upgrading to rails 3.1.1.rc1 I had similar errors as mentioned here. The solution was to add require "sprockets/railtie" to application.rb.

@sush

My project is using require "rails/all" and after having tried your solution it's still doesn't work...

@assembler

I have the same issue.

asset-url("foo.bar", image) -> resolves to "url(/assets/foo.bar)"
image-url("foo.bar") -> resolves to "url(/images/foo.bar)"

I'm using rails 3.1.0 and sass-rails 3.1.0

@spastorino
Ruby on Rails member

Can you guys test using Rails 3-1-stable and sass-rails 3-1-stable branches?.
Thanks.

@sush

It works ! Thanks a lot :)

@avocade

Great, works fine now. Thanks Santiago!

@chriseppstein
@gucki

@chriseppstein I thought long lived asset references (ex. email) is actually an example why digest-based urls are good/ needed. So html, css and images all match the same version.

So if you have long lived stuff, just don't clean up the assets folder. Or enhance the assets rake task, so that you can pass a timestamp, so only assets older than xxx days are removed.

@avocade

Good point about the email, just didn't see these being generated before in 3.1.0 and earlier 3-1-stable commits.

That's why I was wondering if this was a new bug introduced with the latest changes.

@shir

Have same issue after updating from rails 3.1.1.rc4 to 3.1.1. After investigating found gem sass-rails with 3.1.0rc4 version. After updating to sass-rails to 3.1.4 all became work well.

@assembler

This still does not work for me even with rails 3.1 and sass-rails 3.1.4

asset-url('foo.png', image) # /assets/foo.png
image-url('foo.png') # /images/foo.png

@chriseppstein

@assembler do you have compass installed? If so, what version?

@assembler

Yes I do.. 0.11.5

@assembler

Here is my complete gemfile

source 'http://rubygems.org'

gem 'rails', '3.1.1'

gem 'pg'
gem 'jquery-rails'
gem 'devise'
gem 'formtastic'
gem 'countries'
gem "recaptcha", require: "recaptcha/rails"
gem 'gravtastic'



group :assets do
  gem 'sass-rails',  "~> 3.1.4"
  gem 'coffee-rails', "~> 3.1.1"
  gem 'yui-compressor'
  gem 'compass'
end

group :development do
  gem 'ruby-debug19', require: 'ruby-debug'
  gem 'rails-erd'
end

group :test, :development do
  gem 'thin'
  gem "rspec-rails", "~> 2.6"
  gem 'valid_attribute'
end

group :test do
  gem 'capybara'
  gem 'launchy'
  gem 'email_spec'

  gem 'factory_girl_rails'
  gem 'spork', '~> 0.9.0.rc'

  gem 'growl'
  gem 'guard-rspec'
  gem 'guard-spork'

  gem 'timecop'
  gem 'webmock'

  gem 'simplecov', require: false
end
@alexdreher

After upgrading from Rails 3.1.0, where everything was working, I now run into the same problem (image-url not working, asset-url is). I made a full bundle update, so everything should be up to date.

I was a bit confused, because I am not using Compass in this project, with which the error occured before. So I appended my complete Gemfile.lock, maybe it is helping for tracing down this bug.

https://gist.github.com/1308971

UPDATE: Forget about it, I used 3.1.4... With sass-rails (3.1.5.rc.1) everything works as expected. Nice!

@betelgeuse

I am hitting this bug with the following latest gems:

  • rails 3.1.1
  • sass-rails-3.1.5.rc.1
  • sass-3.1.10
  • no compass

I also made sure to test with caches cleared

@chriseppstein should this be reopened?

@betelgeuse

@chriseppstein: after removing tmp/cache/assets in addition to sass caches it's working again

@khelal

We are on Rails 3.1.3 and haml 3.1.3 and still having the same problem.

All images rendered from CSS are correctly transformed into the /assets/ url, but all the images called directly from the haml template are being rendered with the old /images/ url...

I've tried all the cache clearing recommendations suggested above, and still the same. Any ideas?

@xanview

Having the same issue here :/

@e3matheus

Same issue in Rails 3.1.3. A downgrade to Rails 3.1.1 worked for me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment