Prevent Google maps JS executing multiple times caused by Rails Turbolinks

前端 未结 5 1314
盖世英雄少女心
盖世英雄少女心 2021-02-19 07:30

I\'m currently working on Rails app that is getting the following error:

You have included the Google Maps API multiple times on this page. This may ca

5条回答
  •  花落未央
    2021-02-19 08:03

    Try this too....

    google.maps.event.addDomListener(window, 'turbolinks:load', initialize);

    And remeber, all google script have to stay after Turbolink, like this:

    = javascript_include_tag 'application', 'data-turbolinks-track': 'reload'
    = javascript_include_tag 'https://maps.googleapis.com/maps/api/js', 'data-turbolinks-track': 'reload'
    = javascript_include_tag 'gmap', 'data-turbolinks-track': 'reload'
    

    See more at: https://github.com/turbolinks/turbolinks

提交回复
热议问题