有没有办法包含/ assets / javascripts中的所有内容?

时间:2013-06-13 23:09:34

标签: ruby-on-rails include

正如它在锡上所说的那样。似乎javascript_include_tag :all包含/assets/all.js而不是所有这些。

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

1 个答案:

答案 0 :(得分: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文件放入输出中。这些   必须相对于清单文件指定路径。你也可以   使用包含所有JavaScript的require_directory指令   文件只在指定的目录中,没有递归。