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

Not work on Rails 4 beta 1 production asset pipeline #24

Closed
leckylao opened this issue Apr 23, 2013 · 10 comments
Closed

Not work on Rails 4 beta 1 production asset pipeline #24

leckylao opened this issue Apr 23, 2013 · 10 comments

Comments

@leckylao
Copy link

Here's the link for my test app: https://github.com/lecky/test_error

the asset_path seems not returning the correct url with the hash code. Here's what I got from the browser.

@font-face {
  font-family: 'FontAwesome';
  src: url('/assets/fontawesome-webfont.eot');
  src: url('/assets/fontawesome-webfont.eot?#iefix') format('embedded-opentype'),
    url('/assets/fontawesome-webfont.woff') format('woff'),
    url('/assets/fontawesome-webfont.ttf') format('truetype');
  font-weight: normal;
  font-style: normal;
}
@rmm5t
Copy link
Collaborator

rmm5t commented Apr 23, 2013

@lecky Is this related to #22?

@leckylao
Copy link
Author

Hi @rmm5t, Thanks for the reply. I don't think it's the same issue as I didn't see any errors or file not found.

This issue is it works on development, but on production the helper method not returning the correct asset url with hash appended.

@rmm5t
Copy link
Collaborator

rmm5t commented Apr 24, 2013

Just to confirm before I dig deeper, do you have config.assets.digest = true in production.rb? Also, are the digests working correctly for you in Rails 3.2?

@rmm5t
Copy link
Collaborator

rmm5t commented Apr 24, 2013

@lecky Initial testing against our test suite (with config.assets.digest = true) against both Rails 4.0.0.beta1 and Rails master shows the digests working correctly.

However, when I try to compile assets in your test_error project, I get the following error.

$ bundle exec rake assets:precompile RAILS_ENV=production
rake aborted!
couldn't find file 'font-awesome'
  (in /Users/rmcgeary/work/oss/test_error/app/assets/stylesheets/application.css:12)
/Users/rmcgeary/work/oss/test_error/vendor/ruby/2.0.0/gems/sprockets-2.9.2/lib/sprockets/context.rb:106:in `resolve'
/Users/rmcgeary/work/oss/test_error/vendor/ruby/2.0.0/gems/sprockets-2.9.2/lib/sprockets/context.rb:146:in `require_asset'
/Users/rmcgeary/work/oss/test_error/vendor/ruby/2.0.0/gems/sprockets-2.9.2/lib/sprockets/directive_processor.rb:217:in `process_require_directive'
/Users/rmcgeary/work/oss/test_error/vendor/ruby/2.0.0/gems/sprockets-2.9.2/lib/sprockets/directive_processor.rb:167:in `block in process_directives'
/Users/rmcgeary/work/oss/test_error/vendor/ruby/2.0.0/gems/sprockets-2.9.2/lib/sprockets/directive_processor.rb:165:in `each'
/Users/rmcgeary/work/oss/test_error/vendor/ruby/2.0.0/gems/sprockets-2.9.2/lib/sprockets/directive_processor.rb:165:in `process_directives'
/Users/rmcgeary/work/oss/test_error/vendor/ruby/2.0.0/gems/sprockets-2.9.2/lib/sprockets/directive_processor.rb:99:in `evaluate'
/Users/rmcgeary/work/oss/test_error/vendor/ruby/2.0.0/gems/tilt-1.3.7/lib/tilt/template.rb:77:in `render'
...

@rmm5t
Copy link
Collaborator

rmm5t commented Apr 24, 2013

More information. If I move font-awesome-rails outside the assets group in your test_error Gemfile, everything works as expected (in production env) to compile the assets with the MD5 digests.

@rmm5t
Copy link
Collaborator

rmm5t commented Apr 24, 2013

I think the underlying problem is that Rails expects assets:precompile to be run outside a production environment. Thus config.assets.digest is typically false, and our asset_path usage does not generate urls with the full font assets including the MD5 digests. I actually think this is a problem in Rails 3.2 too. I'm not sure how to fix this considering that we have to utilize the asset_path helper in this engine's stylesheet.

Any ideas?

@rmm5t
Copy link
Collaborator

rmm5t commented Apr 24, 2013

@lecky I take everything back. It seems that everything is working as expected. It seems that Rails 4 just requires the RAILS_GROUPS env variable to correctly compile assets. For example, try running:

$ bundle exec rake assets:precompile RAILS_ENV=production RAILS_GROUPS=assets

@rmm5t rmm5t closed this as completed Apr 24, 2013
@leckylao
Copy link
Author

Hi @rmm5t , greate found ❗ 👍 The issue is with the rake task RAILS_ENV

This one works:
bundle exec rake assets:precompile RAILS_ENV=production
And this one doesn't:
bundle exec rake assets:precompile

Not sure what got changed on Rails 4, but on the official guide http://guides.rubyonrails.org/asset_pipeline.html. The RAILS_ENV is not required.

@Shahor
Copy link

Shahor commented Jul 12, 2013

Thanks @lecky ! this just solved my problem 😄

Not sure why the RAILS_ENV=production is mandatory though =/ Seems like a useless param here.

@jzamanski
Copy link

Thank you, @leckylao, I agree @Shahor, seems like production should be the default. Maybe I just don't have my head wrapped around the asset pipeline yet.

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

4 participants