Rails 3.1 Asset Pipeline 清单文件不会获取 javascript
我在vendor/assets/javascripts中有一大堆乱七八糟的javascripts。在我的 app/assets/javascripts/application.js 文件中,我有指令:
//= require_tree .
是否仅引用当前的 app/assets/javascripts 目录,而不引用 lib/assets 或vendor/assets?
如果我明确包含 JavaScript,它就可以工作。如果不需要的话我真的不想这么做。
我是否缺少一些东西,可以让资产管道能够自动从应用程序目录(lib 和供应商)外部提供资产?
I have a whole MESS of javascripts in vendor/assets/javascripts. In my app/assets/javascripts/application.js file, I have the directive:
//= require_tree .
Does that only reference the current app/assets/javascripts directory, and not lib/assets or vendor/assets?
If I explicitly include the javascripts, it works. I just don't really want to do that if I don't have to.
Is there something I am missing that will allow the assets pipeline to be able to serve up assets from outside the app directory (lib and vendor) automatically?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
require_tree 仅提取 application.js 文件下的资源。
lib/assets
和vendor/assets
已包含在管道的查找路径中 (参考此代码)。您可以使用第二个清单包含这些供应商的文件。
转到vendor/assets/javascripts并创建一个名为misc_vendor.js的文件
,在其中添加一个require_tree指令。
然后从您的 application.js 清单中引用该文件:
如果您因加载顺序而遇到任何问题,您可以按照您需要的顺序手动请求供应商文件,而不是使用 require_tree。
作为管道转换的一部分,这可能是清理东西的好机会! :-)
require_tree only pulls in assets that are under the application.js file.
lib/assets
andvendor/assets
are already included in the lookup paths for the pipeline (refer this code).You can include these vendored files by using a second manifest.
Go to
vendor/assets/javascripts
and create a file called misc_vendor.jsInside that add put a require_tree directive.
Then refer to that file from your application.js manifest:
If you have any issues because of loading order you can manually require the vendor files in the order you need instead of using require_tree.
As part of the conversion to the pipeline it may be a good chance to clean up things! :-)
另外,您可以在没有第二个清单的情况下执行此操作,如下所示:
路径应相对于“app/assets/javascripts/application.js”清单文件。
Also, you can do it without a second manifest like this:
The path should be relative to the 'app/assets/javascripts/application.js' manifest file.
您需要像这样扩展 application.rb 文件中的路径。
请参阅本指南了解更多详细信息
You need to extend path in application.rb file like this.
Refer this Guide for more details