【问题标题】:Is there a way to include everything that's in /assets/javascripts?有没有办法包含 /assets/javascripts 中的所有内容?
【发布时间】:2013-06-13 23:09:34
【问题描述】:

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

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

【问题讨论】:

  • 是的,这实际上是资产管道的主要目的之一。使用清单。

标签: ruby-on-rails include


【解决方案1】:

为什么不直接使用默认生成的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 指令 文件只在指定的目录中,没有递归。

【讨论】:

    猜你喜欢
    • 2012-02-18
    • 1970-01-01
    • 2017-06-30
    • 2013-04-10
    • 1970-01-01
    • 1970-01-01
    • 2011-02-01
    • 1970-01-01
    相关资源
    最近更新 更多