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

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

Closed
rickclare opened this issue Aug 31, 2011 · 20 comments
Closed

Comments

@rickclare
Copy link

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

muxcmux commented Aug 31, 2011

correct method is asset_url, not asset-url

@flop
Copy link
Contributor

flop commented Aug 31, 2011

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

@rickclare
Copy link
Author

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

https://github.com/rails/sass-rails

@flop
Copy link
Contributor

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

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
      end

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

@rickclare
Copy link
Author

Apologies @flop

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

config.assets.compile = true

@flop
Copy link
Contributor

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

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

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

@flop
Copy link
Contributor

flop commented Aug 31, 2011

Yep it working fine now on 3-1-stable

@flop
Copy link
Contributor

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 ;)

@gucki
Copy link

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

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

@gucki
Copy link

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

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

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

@gucki
Copy link

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

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

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

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.

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

7 participants