Ruby on Rails 3.1 RC1 Javascript 资产管道问题

发布于 2024-11-14 18:20:39 字数 538 浏览 4 评论 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 文件。

谢谢!

I have just upgraded to Rails 3.1, and I am having an issue with loading my Javascripts with the new asset pipeline.

I have copied the js files (both the files themselves and their .min variants) into my /app/assets/javascripts directory, and my application.js manifest is as follows:

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

But this does not appear to be working; Easytabs is not being loaded correctly. Strangely, when I look in the console at the application.js file that is compiled, I can see the Easytabs code, but it is not working.

I have found that if i paste the code directly into the application.js file, it works as expected, so I know that the script is working. This is not, however, the intended use of the application.js file.

I would appreciate any guidance on where to go next in order to ensure the correct loading of the js files.

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

如此安好 2024-11-21 18:20:39

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

vendor/assets/javascripts/

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

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

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

Try moving all your plugins (like easytabs) into the vendor directory.

vendor/assets/javascripts/

Then change your application.js file to this:

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

You should (if you aks me) only place code that you have written for a specific controller in your app/assets/javascripts directory, everything else, like plugins should go in the vendors dir.

骄傲 2024-11-21 18:20:39

我设法弄清了这一点 - 似乎要求顺序是按字母顺序排列的,因此 jquery_easytabs 在 jquery_ujs 之前编译。我通过重命名为 jquery_zeasytabs 修复了这个问题 - 不是最干净的,但它确实有效。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文