问题描述
我一直在将应用程序转换到 Rails 3.1(现在转换到 3.2)并观看了 资产管道上的 Railscast.我将所有第三方 jquery 插件文件移动到/vendor/assets/javascripts/目录.在我的/app/assets/javascripts/application.js 中,我有以下内容:
I've been transitioning an app to Rails 3.1 (and now on to 3.2) and watched the Railscast on the asset pipeline. I moved all of my third-party jquery plugin files to the /vendor/assets/javascripts/ directory. In my /app/assets/javascripts/application.js I have the following:
//= require jquery
//= require jquery_ujs
//= require_tree .
//= require_self
我意识到 require_tree .
调用只加载/app/assets/javascripts/目录的树.(这是正确的吗?)包含所有供应商"javascript 的最佳方法是什么?(此时我并不担心订购.)当然,我可以在/app/assets/javascripts/application.js 中逐行要求它们.我的另一个想法是使用以下内容创建/vendor/assets/javascripts/vendor_javascripts.js:
I realized the require_tree .
call only loads the tree for the /app/assets/javascripts/ directory. (Is that correct?) What's the best way to include all the "vendor" javascripts? (I'm not worried about ordering at this point.) Of course I could require them line by line in /app/assets/javascripts/application.js. My other thought was to create /vendor/assets/javascripts/vendor_javascripts.js with the following:
//= require_tree .
然后在/app/assets/javascripts/application.js 添加以下内容:
And then in /app/assets/javascripts/application.js add the following:
//= require vendor_javascripts
不过这看起来有点笨拙.有没有更好的方法来自动包含所有供应商"(和/或lib")javascripts?
This seems a little clunky though. Is there a better way to automatically include all the "vendor" (and/or "lib") javascripts?
附注.我看到了这个关于 index.js 文件,但我可能最终会有多个名为 index.js 的文件,对吗?哦,我一直在尝试重新启动服务器.
PS. I saw this about index.js files, but I would potentially end up with multiple files named index.js, right? Oh, and I tried restarting my server throughout.
推荐答案
您可以在您的 app/assets/javascripts/application.js
文件中添加类似的内容以包含所有供应商 javascripts:
You can add something like this in your app/assets/javascripts/application.js
file to include all the vendor javascripts:
//= require_tree ../../../vendor/assets/javascripts/.
这篇关于Rails 资产管道:包含所有/vendor/assets/javascripts/?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!