Application.js 没有被处理成最终视图

Application.js is not being processed into final view

我的 application.html.erb 布局中有这样一行:

<%= javascript_include_tag 'application', media: 'all', 'data-turbolinks-track' => true %>

但是在发送到浏览器的 html 页面中我只找到

<script src="/assets/application.self-877aef30ae1b040ab8a3aba4e3e309a11d7f2612f44dde450b5c157aa5f95c05.js?body=1" media="all" data-turbolinks-track="true"></script>

其中包含 'nothing'

(function() {

}).call(this);


在我的 /app/assets/javascripts/application.js 我有

//= require jquery.min
//= require jquery_ujs
//= require bootstrap.min

和我的 /vendor/assets/javascripts/ 包括 jquery.min.jsbootstrap.min

我的 Gemfile 包括

gem 'jquery-rails'
gem 'sprockets-rails'
gem 'turbolinks'

我现在的解决方法是将 jquery 和 bootstrap javascript 直接包含在

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>

有用的信息

$uname -a
Linux Kasama 4.0.6-1-ARCH #1 SMP PREEMPT Tue Jun 23 14:25:08 CEST 2015 x86_64 GNU/Linux

$rails --version
Rails 4.2.3

$ruby --version
ruby 2.2.3p173 (2015-08-18 revision 51636) [x86_64-linux]

可以找到整个应用程序的源代码here(感谢任何建设性的批评)


根据我从 The Asset Pipeline 中读到的内容,我所拥有的应该可以正常工作,但事实并非如此。


旁注:application.css 清单被正确加载并且 bootstrap.css 文件被发送到浏览器,问题只发生在 javascript 文件

请参阅文档的开发中部分:

http://guides.rubyonrails.org/asset_pipeline.html#in-development

In development mode, assets are served as separate files in the order they are specified in the manifest file.

你的 js/css 资产在那里,在分开的 script/link 标签中。

更新 在您的情况下,问题是由 application.coffee 文件引起的,该文件与 application.js 一起出现。删除它会解决您的问题。