0

My rails app load application.js functions only when im refresh the page,in other case (site surfing,AJAX operations) it doesent.So how to load application.js every server-client actions?Every function pulled inside the

 $(document).ready(function() {
nikolay
  • 112
  • 9

1 Answers1

1

$(document).ready(function() { will not work properly with Turbolinks enabled since it'll be triggered just once, you want to use this instead:

var ready;
ready = function() {

  ...your javascript goes here...

};

$(document).ready(ready);
$(document).on('page:load', ready);

See this link for more information: Rails 4: how to use $(document).ready() with turbo-links

Community
  • 1
  • 1
tirdadc
  • 4,603
  • 3
  • 38
  • 45
  • Doing that insures your JS gets loaded properly and if you have callbacks set up to react to AJAX events, they should work as is. You can read more about JS/AJAX with Rails 4 here: http://guides.rubyonrails.org/working_with_javascript_in_rails.html – tirdadc May 04 '15 at 18:30