apneadiving / Google-Maps-for-Rails

Enables easy Google map + overlays creation in Ruby apps
https://apneadiving.github.io/
MIT License
2.27k stars 382 forks source link

Gmaps is not defined #549

Open MiguelFCoelho opened 7 years ago

MiguelFCoelho commented 7 years ago

I´m developing an website in ROR

I am using gem 'gmaps4rails'.

In localhost the map is showed, but when i put on a production server (DigitalOcean) gives me this error: Uncaught ReferenceError: Gmaps is not defined

i have this script in my index.html.erb:

<div id="map_show" ></div>
</div>
<script type="text/javascript">  
      handler = Gmaps.build('Google');
handler.buildMap({ provider: {}, internal: {id: 'map_show'}}, function(){
 markers = handler.addMarkers(<%=raw @hash.to_json %>);

  handler.bounds.extendWith(markers);
  handler.fitMapToBounds();
});
        </script>

My application.js is this:

//= require jquery
//= require bootstrap-sprockets
//= require jquery_ujs
//= require turbolinks
//= require underscore
//= require gmaps/google
//= require highcharts
//= require chartkick 
//= require_tree .

Anyone know how can i resolve my problem?

buncis commented 7 years ago

this is turbolinks related, try to disable turbolinks and you'll be fine, or load the gmaps in head/allpages.

LindaKadz commented 5 years ago

Did you ever fix this problem, I'm facing this problem and I cannot find my way out.

MiguelFCoelho commented 5 years ago

Yep. I need to use the CDN:

<script src='//cdn.jsdelivr.net/gmaps4rails/2.1.2/gmaps4rails.js'> </script>
<script src='//cdnjs.cloudflare.com/ajax/libs/underscore.js/1.8.3/underscore.js'> </script>

I ask the same question in StackOverflow:

https://stackoverflow.com/questions/44704324/gmaps-is-not-defined