rails 4 with turbolinks and window load

前端 未结 1 900
隐瞒了意图╮
隐瞒了意图╮ 2020-12-19 04:03

I\'m using Rails 4.

I\'m trying to use this script to show google maps. I got a page with different places and each place got an address. It shows in google maps.

相关标签:
1条回答
  • 2020-12-19 04:33

    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.

    0 讨论(0)
提交回复
热议问题