Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
avocade opened this issue Sep 26, 2011 · 32 comments
Closed

Comments

@avocade
Copy link

avocade commented Sep 26, 2011

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
Copy link
Author

avocade commented Sep 26, 2011

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
Copy link

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
Copy link
Author

avocade commented Sep 26, 2011

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

@avocade
Copy link
Author

avocade commented Sep 26, 2011

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 as completed Sep 26, 2011
@avocade
Copy link
Author

avocade commented Sep 26, 2011

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
Copy link
Contributor

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

@avocade
Copy link
Author

avocade commented Sep 26, 2011

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

Much appreciated!

@guilleiguaran
Copy link
Member

Try with rake tmp:cache:clear

@avocade
Copy link
Author

avocade commented Sep 26, 2011

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
Copy link
Contributor

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

@sush
Copy link

sush commented Sep 27, 2011

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
Copy link
Author

avocade commented Sep 27, 2011

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
Copy link

gucki commented Sep 27, 2011

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
Copy link

sush commented Sep 27, 2011

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

@assembler
Copy link

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
Copy link
Contributor

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

@sush
Copy link

sush commented Sep 29, 2011

It works ! Thanks a lot :)

@avocade
Copy link
Author

avocade commented Sep 29, 2011

Great, works fine now. Thanks Santiago!

@chriseppstein
Copy link
Contributor

Pretty sure this is intentional. Long lived links (like in an email) need to avoid digest-based URLs.

Hunt & pecked on my iPhone... Sorry if it's brief!

On Sep 29, 2011, at 7:05 AM, Oskar Lissheim-Boethiusreply@reply.github.com wrote:

Small question, though. It seems rake assets:precompile now produces both digest:ed filenames and the original filnames (which wastes a lot of space especially with images). Before it just produced digest:ed ones.

Is this intentional?

Reply to this email directly or view it on GitHub:
#57 (comment)

@gucki
Copy link

gucki commented Sep 29, 2011

@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
Copy link
Author

avocade commented Sep 29, 2011

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
Copy link

shir commented Oct 20, 2011

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
Copy link

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
Copy link
Contributor

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

@assembler
Copy link

Yes I do.. 0.11.5

@assembler
Copy link

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
Copy link

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
Copy link

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
Copy link

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

@khelal
Copy link

khelal commented Nov 26, 2011

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?

@tetherit
Copy link

Having the same issue here :/

@e3matheus
Copy link

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
Labels
None yet
Projects
None yet
Development

No branches or pull requests