在我的application.html.haml中
=stylesheet_link_tag "application", :media => "all"
=javascript_include_tag "jquery-1.11.0.min"
=javascript_include_tag "jquery-ui-1.10.4.min"
=javascript_include_tag "angular.min"
=javascript_include_tag "angular-route.min"
=javascript_include_tag "angular-resource.min"
=javascript_include_tag "angular-ui-router.min"
这些js文件当前位于我的app/assets/javascripts文件夹中
当我将它部署到heroku时,我不断得到
3848+00:00 app[web.1]: 9: =stylesheet_link_tag "application", :media => "all"
2014-05-01T21:25:16.063849+00:00 app[web.1]: 10: =javascript_include_tag "jquery-1.11.0.min.js"
2014-05-01T21:25:16.063846+00:00 app[web.1]: ActionView::Template::Error (html5shiv.js isn't precompiled):
2014-05-01T21:25:15.995499+00:00 app[web.1]: Started GET "/" for 128.31.34.63 at 2014-05-01 21:25:15 +0000
2014-05-01T21:25:16.051098+00:00 app[web.1]: Rendered home/index.html.haml within layouts/application (10.3ms)
2014-05-01T21:25:16.063843+00:00 app[web.1]:
2014-05-01T21:25:16.063851+00:00 app[web.1]: 11: =javascript_include_tag "jquery-ui-1.10.4.min.js"
2014-05-01T21:25:16.063853+00:00 app[web.1]: 12: =javascript_include_tag "html5shiv.js"
2014-05-01T21:25:16.063854+00:00 app[web.1]: 13: =javascript_include_tag "angular.min.js"
2014-05-01T21:25:16.063858+00:00 app[web.1]: 15: =javascript_include_tag "angular-resource.min.js"
2014-05-01T21:25:16.063856+00:00 app[web.1]: 14: =javascript_include_tag "angular-route.min.js"
2014-05-01T21:25:16.063860+00:00 app[web.1]: app/views/layouts/application.html.haml:12:in `_app_views_layouts_application_html_haml___1963393475950734090_70074639367120'
我不断收到 Assets 编译错误。我应该在我的 application.js 中要求它们吗?在我的 application.js 中我有这些
//= require jquery_ujs
//= require bootstrap
//= require_tree .
我将其添加到我的 config/environments/Production.rb
config.assets.precompile += %w(email.css event_creation_dynamic_form.js jquery-1.11.0.min.js jquery-ui-1.10.4.min.js angular.min.js angular-route.min.js)
这对我来说并没有真正的作用。我不太熟悉rails中的 Assets 管道以及heroku Assets 管道的工作原理。我也尝试过运行
heroku run rake assets:precompile
而且我的 javascript 文件都是缩小版本。我希望这是正确的生产版本。 我是否正确使用了 js include 标签?
最佳答案
看起来 Heroku 已经方便地告诉您问题所在:
ActionView::Template::Error (html5shiv.js isn't precompiled)
因此您需要将该文件添加到预编译数组中,如下所示:
config.assets.precompile += %w(html5shiv.js, any-other-files-here)
话虽如此,为了回答你的问题,不,你并没有真正正确地使用 js include 标签。
您应该将这些 js 文件包含在 application.js 中。这样,这些文件将与 application.js 一起预编译,并且您不必将它们添加到预编译路径中。例如,在 application.js 中:
//= require path/to/jquery-1.11.0.min.js
//= require path/to/jquery-ui-1.10.4.min.js
//= require path/to/angular.min.js
//= require path/to/angular-route.min.js
//= require path/to/angular-resource.min.js
//= require path/to/angular-ui-router.min.js
关于Heroku 上的 Javascript Assets 编译错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23420071/