0

正如锡上所说。似乎javascript_include_tag :all包括/assets/all.js而不是全部。

有没有办法只包含那里的所有内容以及所有子文件夹?

4

1 回答 1

3

为什么不直接使用默认生成的application.js

/app/assets/javascripts/application.js

// This is a manifest file that'll be compiled into application.js, which will include all the files
// listed below.
//
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
// or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
//
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
// the compiled file.
//
// WARNING: THE FIRST BLANK LINE MARKS THE END OF WHAT'S TO BE PROCESSED, ANY BLANK LINE SHOULD
// GO AFTER THE REQUIRES BELOW.
//
//= require jquery
//= require jquery_ujs
//= require_tree .

记下最后一行://= require_tree .这应该包括你所有的 javascript。

/app/view/layouts/application.html.erb

<%= javascript_include_tag "application" %>

http://guides.rubyonrails.org/asset_pipeline.html#manifest-files-and-directives

require_tree 指令告诉 Sprockets 递归地将指定目录中的所有 JavaScript 文件包含到输出中。这些路径必须相对于清单文件指定。您还可以使用 require_directory 指令,该指令仅包含指定目录中的所有 JavaScript 文件,而无需递归。

于 2013-06-13T23:15:50.740 回答