0

My rails application does not seem to be loading some javascript behavior after being sent to a page via the link_to helper. This is happening in Chrome, but not IE (which hurts me to say). 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. These will work after I reload the page from Chrome, but not off of the initial link_to.

Here is my 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? Please let me know if I can provide any additional information that will be helpful to resolve this.

kevin_j_m
  • 13
  • 3
  • 1
    possible duplicate of [Rails 4 turbo-link prevents jQuery scripts from working](http://stackoverflow.com/questions/18769109/rails-4-turbo-link-prevents-jquery-scripts-from-working) – Mike Campbell Dec 18 '13 at 15:49
  • Hi Mike, you're right; removing turbo-links resolved this issue. Can you move your comment into an answer so I can accept it, or is there another method by which I can confirm this is a duplicate? – kevin_j_m Dec 18 '13 at 15:56
  • I think it goes for moderator attention, but for what it's worth I'll post an answer incase the different wording attracts other folk struggling with this. – Mike Campbell Dec 18 '13 at 16:45

1 Answers1

2

I can see from your application.js that you're using turbolinks.

When using turbolinks, $(document).ready(function() { .. is ignored when clicking on internal links because the page never actually reloads in the traditional way.

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:

  1. removing it from your Gemfile
  2. remove the //= require turbolinks from your application.js
  3. remove the 2 references to "data-turbolinks-track" => true in your layouts/application.html.erb.
Mike Campbell
  • 7,921
  • 2
  • 38
  • 51