GMaps4Rails and Turbolinks not loading without full page refresh

前端 未结 6 1722
悲哀的现实
悲哀的现实 2020-12-28 09:32

I\'m using gmaps4rails to load a map on a \"clients\" show page. I\'ve integrated turbolinks to make the app speadier all together, but now I\'m hitting an issue where I hav

6条回答
  •  轮回少年
    2020-12-28 09:51

    You can use the callback directly from the google map URL

    
    <%= gmap_scripts(callback: 'onGmapsInit') %>
    

    And my helper

    # helpers/maps_helper.rb
    module MapsHelper
      GMAPS_V3_URL = 'https://maps.googleapis.com/maps/api/js'
    
      def gmap_scripts(options = {})
        callback = options.delete(:callback)
        gmaps_v3_options = {
          src: "#{GMAPS_V3_URL}?#{callback ? "callback=#{callback}&" : ''}key=&sensor=false"
        }
        gmaps_utility_options = {
          src: '//google-maps-utility-library-v3.googlecode.com/svn/tags/markerclustererplus/2.0.14/src/markerclusterer_packed.js'
        }
        capture do
          concat content_tag(:script, nil, gmaps_v3_options)
          concat content_tag(:script, nil, gmaps_utility_options)
        end
    end
    

    What ? Turbolinks ? Is it something to eat ?

    I'm using Turbolinks 5, and as you can see with this code you don't even need a

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

提交回复
热议问题