简体   繁体   English

Rails没有从link_to加载Chome中的js

[英]Rails not loading js in Chome from link_to

My rails application does not seem to be loading some javascript behavior after being sent to a page via the link_to helper. 在通过link_to帮助程序发送到页面后,我的rails应用程序似乎没有加载一些javascript行为。 This is happening in Chrome, but not IE (which hurts me to say). 这种情况发生在Chrome中,但不是IE(这让我很伤心)。 I've seen Chrome not loading behavior in multiple pages for bootstrap-switch, and for some custom functions that I have in my source tree. 我已经看到Chrome没有在bootstrap-switch的多个页面中加载行为,以及我在源代码树中的一些自定义函数。 These will work after I reload the page from Chrome, but not off of the initial link_to. 这些在我从Chrome重新加载页面后起作用,但不会从初始link_to开始。

Here is my application.js: 这是我的application.js:

//= require jquery
//= require jquery_ujs
//= require turbolinks
//= require_tree .
//= require bootstrap
//= require bootstrap-switch
//= require jquery-placeholder
//= require jquery_nested_form

Is there some known limitation in how Chrome receives or renders javascript from the link_to helper? Chrome从link_to帮助程序接收或呈现javascript的方式是否存在一些已知限制? Please let me know if I can provide any additional information that will be helpful to resolve this. 如果我能提供有助于解决此问题的任何其他信息,请与我们联系。

I can see from your application.js that you're using turbolinks . 我可以从你的application.js看到你正在使用turbolinks

When using turbolinks, $(document).ready(function() { .. is ignored when clicking on internal links because the page never actually reloads in the traditional way. 当使用turbolinks时,单击内部链接时会忽略$(document).ready(function() { ..因为页面实际上从未以传统方式重新加载。

You have a couple of alternatives, rewrite/restructure your JS so that it plays nicely with turbolinks (by not having page-specific JS includes, by scoping your events appropriately, etc) or you can disable turbolinks if you don't want to use it by: 你有几个选择,重写/重组你的JS,以便它与turbolinks很好地配合(通过没有特定于页面的JS包括,通过适当地确定你的事件等),或者如果你不想使用你可以禁用turbolinks它由:

  1. removing it from your Gemfile Gemfile删除它
  2. remove the //= require turbolinks from your application.js application.js删除//= require turbolinks
  3. remove the 2 references to "data-turbolinks-track" => true in your layouts/application.html.erb . layouts/application.html.erb删除对"data-turbolinks-track" => true的2个引用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM