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

Already on GitHub? Sign in to your account

Rails 3.1.0 - asset:precompile fails when using asset_url() SASS function #2765

rickclare opened this Issue Aug 31, 2011 · 20 comments


None yet
7 participants

I receive a error, after upgrade from Rails 3.1.0.rc6 to Rails 3.1.0,
This is occurring when I use the sass-rails asset_url method:

rake assets:precompile --trace
** Invoke assets:precompile (first_time)
** Execute assets:precompile
rake aborted!
bg_body.png isn't precompiled
 (in //workshop/app/assets/stylesheets/style.css.scss)

The line in style.css.scss (required in application.css) is:

body {
   background: asset-url('bg_body.png', image);

I have attempted to add the following configuration in application.rb, but this does not fix the problem

config.assets.precompile = %w(*.png *.jp?g *.gif application.css application.js)

muxcmux commented Aug 31, 2011

correct method is asset_url, not asset-url


flop commented Aug 31, 2011

Just got the same problem (I tried with different method : assert_url, assert_path, image_path )

According to the sass-rails documentation - asset-url() is correct (i.e. hyphenated in SASS, underscored in Ruby)



flop commented Aug 31, 2011

You need to set :

config.assets.compile = true

but it seems really weird that is needed to run :

rake assets:precompile

because comment says : "Don't fallback to assets pipeline if a precompiled asset is missed"


flop commented Aug 31, 2011

That's stange. config.assets.compile = true in config/environments/production.rb did the trick.
In my case, here is the culprit method in actionpack-3.1.0/lib/sprockets/helpers/rails_helper.rb :

    def digest_for(logical_path)
      if asset_digests && (digest = asset_digests[logical_path])
        return digest

      if Rails.application.config.assets.compile
        if asset = asset_environment[logical_path]
          return asset.digest_path
        return logical_path
        raise AssetNotPrecompiledError.new("#{logical_path} isn't precompiled")

Apologies @flop

I tried your suggestion again. This DOES solve my problem. Thanks a lot for your help.

config.assets.compile = true

flop commented Aug 31, 2011

@rickclare you're welcome
But it seems to me that it more a workaround than a real solution.
Maybe @guilleiguaran can tell us more about that ?


guilleiguaran commented Aug 31, 2011

Your app must work setting config.assets.compile = false. The error is on the rake task that always should set the value to true during the execution of the task.

Check the fix here: https://github.com/rails/rails/pull/2768/files


guilleiguaran commented Aug 31, 2011

@flop @rickclare can you test with config.assets.compile = false but using Rails from 3-1-stable branch?


flop commented Aug 31, 2011

Yep it working fine now on 3-1-stable


flop commented Aug 31, 2011

Thx @guilleiguaran
Going back on 3-1-stable branch in my Gemfile. Used the 3.1 gem for 3 hours ;)

@spastorino spastorino closed this Sep 1, 2011

gucki commented Sep 14, 2011

Imo it's really bad that for those small but very annyoing bugs no hotfix gets released within a couple of hours. I mean this patch has no side-effects for sure..so why not release early and make many many users of rails happy with an in fact working 3.1 release. Is it that much of work?


spastorino commented Sep 15, 2011

@gucki use 3.1.1.rc1, final version will be available on Friday

gucki commented Sep 15, 2011

@spastorino Thanks! Unfortunately 3.1.1.rc1 does not work for me. bundle exec rake RAILS_ENV=production RAILS_GROUPS=assets assets:precompile runs without any problems now, but on every request I get:

A Sprockets::Helpers::RailsHelper::AssetPaths::AssetNotPrecompiledError occurred in index#index:
  favicon.ico isn't precompiled
  actionpack (3.1.1.rc1) lib/sprockets/helpers/rails_helper.rb:137:in `digest_for'

My production env config looks like this

# Compress JavaScripts and CSS
config.assets.compress = true

# Don't fallback to assets pipeline if a precompiled asset is missed
config.assets.compile = false

# Generate digests for assets URLs
config.assets.digest = true

spastorino commented Sep 15, 2011

@gucki ok let's fix that for 3.1.1, can you show an way to reproduce it? I guess it's just calling the favicon_link_tag.
Anyway would be nice to have an app to reproduce because of all the configs, thanks :)


guilleiguaran commented Sep 15, 2011

@spastorino Actually I was trying using the favicon_link_tag but couldn't reproduce it on production env

gucki commented Sep 15, 2011

@spastorino: Oh, I didnt know favicon_link_tag exists g, I just use image_tag or image_path everywhere. But looking at https://github.com/rails/rails/blob/master/actionpack/lib/sprockets/helpers/rails_helper.rb#L121 and having config.assets.compile = false in production, I suspect we immediately get to raise AssetNotPrecompiledError.new("#{logical_path} isn't precompiled"). I don't see where digest_assets gets populated. I'll try to setup a simple failing app.

gucki commented Sep 15, 2011

Ok, looking at https://github.com/rails/rails/blob/master/actionpack/lib/sprockets/railtie.rb#L29 I see that digest_assets gets populated upon startup using a manifest.yml file, which I assume is generated by rake assets:precompile. I'll check if this file exists and what the contents are. I'll report again in a couple of minutes :)

gucki commented Sep 15, 2011

@spastorino Ok, shame on me. Everything seems to be generated directly, I just found out that the link to this file was outdated and is now named differently. After fixing this, rc1 works like a charm. Sorry and thanks for the great work! :)

avocade commented Sep 25, 2011

+1 for getting 'image not precompiled' errors when using image-url() helpers in sass on 3.1.0. If I went hacky and added .erb to the .scss and .sass files (even though I didn't use any erb stuff), it worked…

Seems to be solved in 3.1.1rc1.

@mlushpenko mlushpenko referenced this issue in activeadmin/activeadmin Feb 22, 2013


css not getting precompiled #483

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