Skip to content
This repository

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

Closed
avocade opened this Issue · 32 comments

14 participants

Oskar Boethius Lissheim Scott Davis Santiago Pastorino Guillermo Iguaran Chris Eppstein Aylic Petit Corin Langosch Milovan Zogovic Ildar Shaynurov Alexander Dreher Petteri Räty Karim Helal xanview Elías Matheus
Oskar Boethius Lissheim

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.

Oskar Boethius Lissheim

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".
Scott Davis

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

Oskar Boethius Lissheim

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_expected = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAyRpVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADw%2FeHBhY2tldCBiZWdpbj0i77u%2FIiBpZD0iVzVNME1wQ2VoaUh6cmVTek5UY3prYzlkIj8%2BIDx4OnhtcG1ldGEgeG1sbnM6eD0iYWRvYmU6bnM6bWV0YS8iIHg6eG1wdGs9IkFkb2JlIFhNUCBDb3JlIDUuMC1jMDYxIDY0LjE0MDk0OSwgMjAxMC8xMi8wNy0xMDo1NzowMSAgICAgICAgIj4gPHJkZjpSREYgeG1sbnM6cmRmPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5LzAyLzIyLXJkZi1zeW50YXgtbnMjIj4gPHJkZjpEZXNjcmlwdGlvbiByZGY6YWJvdXQ9IiIgeG1sbnM6eG1wPSJodHRwOi8vbnMuYWRvYmUuY29tL3hhcC8xLjAvIiB4bWxuczp4bXBNTT0iaHR0cDovL25zLmFkb2JlLmNvbS94YXAvMS4wL21tLyIgeG1sbnM6c3RSZWY9Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC9zVHlwZS9SZXNvdXJjZVJlZiMiIHhtcDpDcmVhdG9yVG9vbD0iQWRvYmUgUGhvdG9zaG9wIENTNS4xIE1hY2ludG9zaCIgeG1wTU06SW5zdGFuY2VJRD0ieG1wLmlpZDpCNzY5NDE1QkQ2NkMxMUUwOUUzM0E5Q0E2RTgyQUExQiIgeG1wTU06RG9jdW1lbnRJRD0ieG1wLmRpZDpCNzY5NDE1Q0Q2NkMxMUUwOUUzM0E5Q0E2RTgyQUExQiI%2BIDx4bXBNTTpEZXJpdmVkRnJvbSBzdFJlZjppbnN0YW5jZUlEPSJ4bXAuaWlkOkE3MzcyNTQ2RDY2QjExRTA5RTMzQTlDQTZFODJBQTFCIiBzdFJlZjpkb2N1bWVudElEPSJ4bXAuZGlkOkI3Njk0MTVBRDY2QzExRTA5RTMzQTlDQTZFODJBQTFCIi8%2BIDwvcmRmOkRlc2NyaXB0aW9uPiA8L3JkZjpSREY%2BIDwveDp4bXBtZXRhPiA8P3hwYWNrZXQgZW5kPSJyIj8%2B0HhJ9AAAABBJREFUeNpi%2BP%2F%2FPwNAgAEACPwC%2FtuiTRYAAAAASUVORK5CYII%3D"
  assert_equal asset_data_url_expected, asset_data_url_match
end
Oskar Boethius Lissheim

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.

Oskar Boethius Lissheim

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.

Santiago Pastorino
Owner

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

Oskar Boethius Lissheim

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

Much appreciated!

Guillermo Iguaran

Try with rake tmp:cache:clear

Oskar Boethius Lissheim

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

Chris Eppstein
Collaborator

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

Aylic Petit

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)

Oskar Boethius Lissheim

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...

Corin Langosch

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.

Aylic Petit

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

Milovan Zogovic

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

Santiago Pastorino
Owner

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

Aylic Petit

It works ! Thanks a lot :)

Oskar Boethius Lissheim

Great, works fine now. Thanks Santiago!

Chris Eppstein
Collaborator
Corin Langosch

@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.

Oskar Boethius Lissheim

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.

Ildar Shaynurov

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.

Milovan Zogovic

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

Chris Eppstein
Collaborator

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

Milovan Zogovic

Yes I do.. 0.11.5

Milovan Zogovic

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
Alexander Dreher

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!

Petteri Räty

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?

Petteri Räty

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

Karim Helal

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?

rbq referenced this issue from a commit
Commit has since been removed from the repository and is no longer available.
xanview

Having the same issue here :/

Elías Matheus

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
Something went wrong with that request. Please try again.