0

前几天我遇到了一些 Ajax 问题,通过单击提交按钮多次提交表单。我做了一些浏览,有人建议我删除我的 public/assets 文件夹,我这样做并重新启动了我的服务器,却发现我的一些 Javascript 库不再正常运行......

这实际上很奇怪,因为我可以使用 Firebug 调试器查看源代码,我可以看到它确实已加载。我试图清除我的缓存,我试图在开发模式下编译我的资产,我尝试重新启动我的系统,这些都不起作用。我的 Javascript 根本没有运行,并且在删除我的 public/assets 文件夹后静默失败。 -见编辑

我如何产生这个问题的快速参考:

  1. 停止的服务器
  2. 已删除的公共/资产
  3. 重新启动服务器并注意到问题
  4. 清除缓存
  5. 再次停止服务器并尝试预编译资产

我尝试过的其他事情:

  1. 在 development.rb 中设置config.serve_static_assets = false,再次预编译并重启服务器
  2. 通过 rails s -e development 验证我在开发模式下运行

  3. 删除了我的 tmp/cache 文件夹

额外的信息:

  • 我正在使用 Rails 版本 3.1.3

  • 我最近开始使用需要我在开发中将 config.cache_classes 设置为 true 的 Gem。我通过将其设置为 false 并重新测试来验证这不是问题。

编辑

进一步的测试表明,我的更改阻止了以下代码的触发:

<script type="text/javascript">
   $(document).ready(function() {
     alert("Hello world!")
   });

</script>

但这很好用:

<script type="text/javascript">
   alert("Hello world!")
</script>

Initially I thought that files weren't being loaded from my Asset pipeline, but instead it looks like my changes caused some kind of conflict behind the scenes. I removed require_tree from my application.js file and attempted to load libraries manually to find that they began to work again, this isn't an ideal fix for me.

4

1 回答 1

0

Found the culprit, two birds with one stone actually. One of my JavaScript files were requiring both jquery and jquery_ujs for a second time when it was already being required in my application.js file which was the cause of my mentioned Ajax problem. The very same file was running script that wasn't enclosed with the jquery document ready wrapper which seemed to have broken everything else.

I believe the problem only presented itself after I deleted my public/assets folder because it was storing an older version of this code which possibly didn't have these challenges.

于 2012-08-03T17:32:15.477 回答