如何在供应商中预编译资产?

时间:2014-02-04 15:29:02

标签: ruby-on-rails rake asset-pipeline precompile

在制作中我遇到了这个错误:

ActionView::Template::Error (vendor/jquery_extras.js isn't precompiled):
    26: = stylesheet_link_tag "application", media: "all"
    27: = javascript_include_tag "application"
    28: 
    29: = javascript_include_tag "vendor/jquery_extras"
    30: = javascript_include_tag "vendor/jquery.ba-bbq"
    31: = javascript_include_tag "vendor/moment-with-langs"
    32: = javascript_include_tag "https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false"
  app/views/layouts/_headers.html.haml:29:in `_app_views_layouts__headers_html_haml__4249496561736037731_30585640'
  app/views/layouts/application.html.haml:12:in `_app_views_layouts_application_html_haml__4179352970330185641_30563940'
  app/controllers/items_controller.rb:82:in `new'

在我的config/environments/production.rb我有:

# Disable Rails's static asset server (Apache or nginx will already do this)
  config.serve_static_assets = false

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

  # 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

  # list of assets that need precompilation in vendor directory
  config.assets.precompile += %w( vendor/jquery_extras.js vendor/jquery.ba-bbq.min.js vendor/moment-with-langs.min.js )

在我的public/assets/我有:

$ ls -1 jquery_extras* jquery.ba-bbq* moment-with-langs*
jquery.ba-bbq.min-ad74c9887b7231076917be90512e14c4.js
jquery.ba-bbq.min-ad74c9887b7231076917be90512e14c4.js.gz
jquery.ba-bbq.min.js
jquery.ba-bbq.min.js.gz
jquery_extras-7eb0ce2de6f2553ef84968dc07cec831.js
jquery_extras-7eb0ce2de6f2553ef84968dc07cec831.js.gz
jquery_extras.js
jquery_extras.js.gz
moment-with-langs.min-c30ecb28ae71b4d324d710136a628b14.js
moment-with-langs.min-c30ecb28ae71b4d324d710136a628b14.js.gz
moment-with-langs.min.js
moment-with-langs.min.js.gz

在我的vendor/assets目录中:

$ ls -1 vendor/assets/
fonts
images
img
javascripts
stylesheets

和:

$ ls -1 vendor/assets/javascripts/
jquery.ba-bbq.min.js
jquery_extras.js
moment-with-langs.min.js

这是我的application.js

//= require jquery
//= require jquery_ujs
//= require arwa
//= require jquery.ui.datepicker
//= require jquery.timepicker
//= require colorbox-rails
//= require twitter/bootstrap
//= require cocoon
//= require arwa
//= require_tree .

我不确定我做错了什么。请你帮助我好吗?

谢谢

1 个答案:

答案 0 :(得分:0)

Assets precompile Guide比较我发现了这个:

config / enviroments / production.rb

中的

config.assets.compress = false
它是guide中的

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

# Choose the compressors to use
# config.assets.js_compressor  = :uglifier
# config.assets.css_compressor = :yui

# 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

# Precompile additional assets (application.js, application.css, and all non-JS/CSS are already added)
# config.assets.precompile += %w( search.js )

如果您正在进行本地编译,look up here for do it之后运行本地编译$ RAILS_ENV=production bundle exec rake assets:precompile