我看到在 Gemfile
中加载了两个 gem,那么加载这两个 gem 还是只使用一个是否有意义?
gem 'jquery-turbolinks'
gem 'turbolinks'
谁能告诉我为什么使用这两种 gem ?
最佳答案
如概述here jquery-turbolinks gem 修复了由于 turbolinks 触发 ajax 请求而不是通常的页面重新加载而不总是触发的绑定(bind)事件。
如果你的 javascript 很少,可以随意删除它,但如果你有一些停止工作的 .bind(...)
事件,请阅读 gem 的文档,你可能可以使用它来从文档中修复它:
But if you have a large codebase with lots of $(el).bind(...) Turbolinks will surprise you. Most part of your JavaScripts will stop working in usual way. It's because the nodes on which you bind events no longer exist.
I wrote jquery.turbolinks to solve this problem in my project. It's easy to use: just require it immediately after jquery.js. Your other scripts should be loaded after jquery.turbolinks.js, and turbolinks.js should be after your other scripts.
关于ruby-on-rails - 使用 Turbolinks 和 jQuery Turbolinks,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22937946/