rails 4 with turbolinks and window load

泄露秘密 提交于 2019-11-29 09:57:28

You need to initialize scripts via turbolinks. Check this ASCIIcast about turbolinks.

In general, you need to change...

jQuery(function() {
  # your script
});

...to...

var ready;
ready = function() {
  # your script
};

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

All turbo links events you can find here.

Update for Turbolinks 5

page:load has changed to turbolinks:load, so instead you want to write:

var ready;
ready = function() {
  # your script
};

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

You no longer need to specify $(document).ready(); as turbolinks:load does that. For more info, check out the README.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!