Heroku 生产:Gmaps 未定义 - 在本地工作

Heroku production : Gmaps is not defined - works in local

本文关键字:工作 未定义 生产 Gmaps Heroku      更新时间:2023-09-26

在一个简单的页面上,我展示了一个带有一个标记的谷歌地图。

在本地,一切都运行良好,但是在 Heroku 上,我在控制台中出现错误:

 Uncaught ReferenceError: Gmaps is not defined

这与

handler = Gmaps.build('Google'); //and some other stuff

在当地,这是有效的。但是当我在 heroku 上部署它时,就像它无法加载 JS 一样。

这是我文件的顶部

<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>
<script src='//google-maps-utility-library-v3.googlecode.com/svn/trunk/richmarker/src/richmarker-compiled.js' type='text/javascript'></script>

application.js

//= require underscore
//= require gmaps/google

我可能不是一个简单的错误,可能与预编译的资产有关,但我不是这个领域的专家

实际上,我解决了我的问题:

我的控制台显示 JQuery 未定义。我并没有太注意它。但这就是问题所在。所以我改变了application.js要求的顺序,并将gmaps放在顶部

//= require gmaps/google
//= require jQuery.headroom.min.js
//= require headroom.min.js    
//= require underscore
//= require template.js

所以 gmaps 在文件顶部,当 JQuery 被声明为 undefined 时,它没有阻止 gmaps 加载。所以现在我必须解决jquery问题,但是这个gmaps问题已经解决了

在本地系统中运行 Rails 服务器时,请始终使用命令"Rails s -e production" 来检查站点在 Heroku 中的工作方式。 您可能应该添加

/

/= require_tree .

到您的应用程序.js..请查看以下链接:

gmaps4rails:未捕获的引用错误:未定义 Gmaps

如果您在 .html.erb 文件上使用标准<script>遇到错误,那么这就是您在 .html.erb 文件上包含 javascript 的方式,否则它可能会显示错误

<%= javascript_include_tag "http://YourJavascriptFileLink.js" %>