0

我刚刚升级到 Rails 3.1,在使用新的资产管道加载我的 Javascript 时遇到问题。

我已将 js 文件(文件本身及其 .min 变体)复制到我的 /app/assets/javascripts 目录中,我的 application.js 清单如下:

//= require jquery
//= require jquery_ujs
//= require jquery-easytabs
//= require jquery-hashchange.min
//= require_tree .

但这似乎不起作用;Easytabs 未正确加载。奇怪的是,当我在控制台中查看编译的 application.js 文件时,我可以看到 Easytabs 代码,但它不起作用。

我发现如果我将代码直接粘贴到 application.js 文件中,它会按预期工作,所以我知道脚本正在工作。但是,这不是 application.js 文件的预期用途。

为了确保正确加载 js 文件,我将不胜感激有关下一步去哪里的任何指导。

谢谢!

4

2 回答 2

0

I managed to get to the bottom of this - it seems that the require order is alphabetical, so jquery_easytabs was getting compiled before jquery_ujs. I fixed this by renaming to jquery_zeasytabs - not the cleanest, but it does work.

于 2011-06-10T21:16:14.687 回答
0

尝试将所有插件(如 easytabs)移动到供应商目录中。

vendor/assets/javascripts/

然后将您的 application.js 文件更改为:

//= require jquery
//= require jquery_ujs
//= require_tree ../../../vendor/assets/javascripts
//= require_tree .

你应该(如果你问我)只将你为特定控制器编写的代码放在你的 app/assets/javascripts 目录中,其他所有东西,比如插件应该放在供应商目录中。

于 2011-06-10T13:31:51.937 回答