gpt4 book ai didi

heroku - Heroku Cedar 的生产中未定义 Gmaps

转载 作者:行者123 更新时间:2023-12-02 06:36:19 27 4
gpt4 key购买 nike

我是RoR新手,所以有很多概念我还不太理解。

作为我在 Rails 上的第一个项目,我根据 Michael Hartl 的教程编写了一个站点。我的网站是在 Rails 3.1.0 中完成的,并且在我的 ubuntu 站上的开发中运行良好。在该站点中,我有 gmaps4rails,它以这种方式加载到 gemfile 中:

gem 'gmaps4rails', "~> 1.4.8" 

我还有另一个名为 timeglider 的控件,它是一个 javacript 控件,位于/public/timeglider 文件夹中的公共(public)文件夹中。

所有这些都在开发中工作,但是当我想在 heroku 上的生产中部署它时,我的 chrome 控制台出现了问题:

http://geojiffy.herokuapp.com/:277Uncaught ReferenceError: Gmaps is not defined
http://geojiffy.herokuapp.com/:182Uncaught ReferenceError: Gmaps is not defined

我邀请您去查看加载页面的结果here 。gmaps 部分中未加载任何内容。

问题在于,当到达第 #277 行时,Gmaps 尚未定义。

当我尝试修复它时,我在 stackoverflow 中阅读了许多有关 sprocket 及其编译 js 文件的方式的其他问题。

我将 application.js 从 *= require_tree . 更改为

//= require jquery-ui
//= require jquery
//= require jquery_ujs
//= require jiffies.js
//= require gmap3.min.js
//= require jquery-1.7.1.min.js
//= require jquery-ui-1.8.16.custom.min.js
//= require gmaps4rails/all_apis.js
//= require gmaps4rails/bing.js
//= require gmaps4rails/gmaps4rails.base.js.coffee
//= require gmaps4rails/gmaps4rails.bing.js.coffee
//= require gmaps4rails/gmaps4rails.googlemaps.js.coffee
//= require gmaps4rails/gmaps4rails.base.js
//= require gmaps4rails/googlemaps.js

这些脚本是由 heroku 在 slug 创建时编译的

您可以访问完整的application.js here您可以找到该脚本中定义 Gmaps 对象的位置。

很明显,rails、gmaps4rails 和 heroku 中有很多我不理解的地方,从而导致了部署问题。我不确定问题是否出在 Assets 管道上。

我在这个错误上花了很多个晚上,但我无法理解调试它的清晰方法。你能给我一些发现 bug 的提示吗?

附注:我想向您发布照片和链接,但我是新人,所以有一些限制

这是我认为的代码:

 <%= gmaps({ "map_options" => { "type" => "ROADMAP",  "zoom" => 10, "detect_location" => true,"center_on_user" => true,"auto_adjust" => false}, 
"markers" => { "data" => @json } }) %>
<div class='timeline-div' id='placement'></div>

$(function () { 
var isGeoChanging = false;
var lastGmapInfoWindowOpen = null;
var lastTgInfoWindowOpen = null;

//*****************************************************
// Code pour les évènements sur control du formulaire
//*****************************************************
$("#btn_change_geo").live('click', function() {
switchGeoChanging();
});


switchGeoChanging = function()
{
if (isGeoChanging)
{
$("#btn_change_geo").html("Change Jiffy's Geo");
isGeoChanging = false;
$("#div_change_geo_info").hide();
}
else
{
$("#btn_change_geo").html("Cancel");
isGeoChanging = true;
$("#div_change_geo_info").show();
}

}

//************************************************
// Code pour les évènements sur le gmap
//************************************************
Gmaps.map.callback = function()
{
for (var i=0; i<this.markers.length; i++)
{
var marker = Gmaps.map.markers[i].serviceObject;
marker.set("id", Gmaps.map.markers[i].id);
google.maps.event.addListener(marker, 'click', function()
{
//ici on cache les infowindow precedament ouvert pour garder la fenêtre à l'ordre
if (lastGmapInfoWindowOpen != null) { lastGmapInfoWindowOpen.infowindow.close(); }
lastGmapInfoWindowOpen = marker;
if (lastTgInfoWindowOpen != null) { lastTgInfoWindowOpen.hide(); }

//ici,si l'option est enclanché, on change la valeur du du geoId qui est associé au Jiffy
if (isGeoChanging)
{
switchGeoChanging();
$("#txt_geo_id").val(this.get("id"));
callAjaxGet("http://localhost:3000/jiffies/"+this.get('id')+"/getGeo");
}

} );
}
marker = null;
};

callAjaxGet = function(url)
{
$.ajax(url, {
type: 'GET',
data: { },
success: function() { },
error: function() { alert("Impossible de charger le Jiffy."); }
});
}


//************************************************
// code pour les évènements sur le timeglider
//************************************************
$(".timeline-table").css({"display":"block"});


var tg1 = $("#placement").timeline({
"min_zoom":5,
"max_zoom":50,
"show_centerline":true,
"data_source":"#jiffies_table",
"show_footer":false,
"display_zoom_level":true,
"event_overflow":"scroll",
"icon_folder":"http://localhost:3000/timeglider/js/timeglider/icons/"
});





$("#scrolldown").bind("click", function() {
$(".timeglider-timeline-event").animate({top:"+=100"})
});

$("#scrollup").bind("click", function() {
$(".timeglider-timeline-event").animate({top:"-=100"})
});

<%= @js_jiffies.html_safe%>



}); // end document-ready

最佳答案

查看网页http://geojiffy.herokuapp.com/ ,有许多 javascript 文件的 URL 路径类似于下面的代码。 http://localhost:3000可以在您的 Dev 机器上运行,但不能在 Heroku 上运行。

<script src="http://localhost:3000/timeglider/js/timeglider/TG_Date.js" type="text/javascript" charset="utf-8"></script> 
<script src="http://localhost:3000/timeglider/js/timeglider/TG_Org.js" type="text/javascript" charset="utf-8"></script>
<script src="http://localhost:3000/timeglider/js/timeglider/TG_Timeline.js" type="text/javascript" charset="utf-8"></script>
<script src="http://localhost:3000/timeglider/js/timeglider/TG_TimelineView.js" type="text/javascript" charset="utf-8"></script>
<script src="http://localhost:3000/timeglider/js/timeglider/TG_Mediator.js" type="text/javascript" charset="utf-8"></script>
<script src="http://localhost:3000/timeglider/js/timeglider/timeglider.timeline.widget.js" type="text/javascript" charset="utf-8"></script>

编辑。从 Chrome 控制台

Failed to load resource http://localhost:3000/timeglider/css/aristo/jquery-ui-1.8.5.custom.cssFailed to load resource http://localhost:3000/timeglider/js/timeglider/Timeglider.cssFailed to load resource application-a4d3485a82d7a76995c8b93a7477f17a.js:315Uncaught ReferenceError: jQuery is not defined http://localhost:3000/timeglider/js/jquery.jsFailed to load resource http://localhost:3000/timeglider/js/jquery-ui.jsFailed to load resource http://localhost:3000/timeglider/js/underscore-min.jsFailed to load resource http://localhost:3000/timeglider/js/backbone-min.jsFailed to load resource http://localhost:3000/timeglider/js/jquery.tmpl.jsFailed to load resource http://localhost:3000/timeglider/js/ba-debug.min.jsFailed to load resource http://localhost:3000/timeglider/js/ba-tinyPubSub.jsFailed to load resource http://localhost:3000/timeglider/js/jquery.mousewheel.min.jsFailed to load resource http://localhost:3000/timeglider/js/jquery.ui.ipad.jsFailed to load resource http://localhost:3000/timeglider/js/raphael-min.jsFailed to load resource http://localhost:3000/timeglider/js/jquery.global.jsFailed to load resource http://localhost:3000/timeglider/js/timeglider/TG_Date.jsFailed to load resource http://localhost:3000/timeglider/js/timeglider/TG_Org.jsFailed to load resource http://localhost:3000/timeglider/js/timeglider/TG_Timeline.jsFailed to load resource http://localhost:3000/timeglider/js/timeglider/TG_TimelineView.jsFailed to load resource http://localhost:3000/timeglider/js/timeglider/TG_Mediator.jsFailed to load resource http://localhost:3000/timeglider/js/timeglider/timeglider.timeline.widget.jsFailed to load resource http://geojiffy.herokuapp.com/assets/defaults.jsFailed to load resource: the server responded with a status of 404 (Not Found) http://geojiffy.herokuapp.com/:149Uncaught ReferenceError: $ is not defined http://geojiffy.herokuapp.com/:277Uncaught ReferenceError: Gmaps is not defined

关于heroku - Heroku Cedar 的生产中未定义 Gmaps,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10308514/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com