简体   繁体   中英

Uncaught ReferenceError: Gmaps is not defined

I'm using Gmaps4rails with Foundation 5. I followed the Gmaps4rails video tutorial and the map is not showing up. I'm getting the Uncaught ReferenceError: Gmaps is not defined and the offending line is the first line of the custom script:

handler = Gmaps.build('Google');

I assume there's some kind of conflict with Foundation because I tried creating a Rails app with only Gmaps4rails and no Foundation and everything works fine.

According to the sample app, the issue is the following: you call Gmaps before the script containing its definition is loaded... it cant work.

Explanation is you put = javascript_include_tag "application" at the bottom of your html, to meet Foundation's expectations. So every previous javascript will fail: you have to put your scripts after the files defining them.

So AFTER = javascript_include_tag "application" , add:

= yield :scripts

And then whenever you need in a view:

- content_for :scripts do
 :javascript
   // Gmaps can be called safely here...

Thanks Benjamin!

I incorporated your suggestion and the map now shows up. Voila!

Checkout https://github.com/JonKernPA/gmaps_zurb to see a full sample app with:

  • Ruby 2.0
  • Rails 4.0
  • gmaps4rails
  • MongoDB
  • Mongo_Mapper
  • Haml
  • Zurb Foundation 5.0

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM