简体   繁体   English

未捕获的ReferenceError:未定义Gmaps

[英]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. 我正在使用Gmaps4rails和Foundation 5.我关注了Gmaps4rails视频教程并且地图没有显示出来。 I'm getting the Uncaught ReferenceError: Gmaps is not defined and the offending line is the first line of the custom script: 我收到了Uncaught ReferenceError: Gmaps is not defined ,违规行是自定义脚本的第一行:

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. 我认为与基金会存在某种冲突,因为我尝试创建一个只有Gmaps4rails并且没有基础的Rails应用程序,一切正常。

According to the sample app, the issue is the following: you call Gmaps before the script containing its definition is loaded... it cant work. 根据示例应用程序,问题如下:在加载包含其定义的脚本之前调用Gmaps ...它无法工作。

Explanation is you put = javascript_include_tag "application" at the bottom of your html, to meet Foundation's expectations. 解释是你在html底部放置= javascript_include_tag "application" ,以满足Foundation的期望。 So every previous javascript will fail: you have to put your scripts after the files defining them. 因此,之前的每个javascript都会失败:您必须在定义它们的文件之后放置脚本。

So AFTER = javascript_include_tag "application" , add: 所以AFTER = javascript_include_tag "application" ,添加:

= 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: 结帐https://github.com/JonKernPA/gmaps_zurb查看完整的示例应用程序:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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