Gmaps is not defined in rails 4 + gmaps4rails 2.0.3

前端 未结 1 348
余生分开走
余生分开走 2021-01-20 05:21

Gmaps4rails is not define in rails 4.0.0 Google Maps for Rails i am following this tutorial \"http://rubydoc.info/gems/gmaps4rails/2.0.4/frames\"

1) Gemfile
         


        
相关标签:
1条回答
  • 2021-01-20 06:12

    I ran into this issue. The problem was that I was loading the map building javascript in the view before I was loading the core gmaps javascript.

    You can solve this by add a yield after your javascripts, and using a content_for block to place your map building javascript after the others. Something like this:

    <script src="//maps.google.com/maps/api/js?v=3.13&amp;sensor=false&amp;libraries=geometry" type="text/javascript"></script>
    <script src='//google-maps-utility-library-v3.googlecode.com/svn/tags/markerclustererplus/2.0.14/src/markerclusterer_packed.js' type='text/javascript'></script>    
    <%= javascript_include_tag "application", "data-turbolinks-track" => true %>  
    <%= yield :javascripts %>
    

    and then, wherever you're building your map,

    <% content_for :javascripts do %>
    <script type='text/javascript'>
        handler = Gmaps.build('Google');
        /* rest of maps building JS */
    </script>
    <% end %>
    
    0 讨论(0)
提交回复
热议问题