Heroku Cedar的生产中没有定义Gmaps

时间:2012-04-25 02:17:23

标签: heroku production pipeline gmaps4rails assets

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

作为我在rails上的第一个项目,我根据Michael Hartl的教程编写了一个站点。 我的网站是在rails 3.1.0中完成的,它在我的ubuntu工作站上的开发工作正常。 在该网站中,我有gmaps4rails,它以gemfile方式加载:

gem 'gmaps4rails', "~> 1.4.8" 

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

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

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

我邀请您查看已加载页面here的结果。 gmaps部分没有加载任何内容。

问题是当Gmaps到达#277行时没有定义它。

当我尝试修复它时,我在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中有很多我不理解的东西会导致部署问题。我不确定问题来自资产管道。

我在这个错误上花了很多个夜晚,我无法理解一个明确的调试方法。你能给我一些提示来找到我的错误吗?

p.s:我想发布你的照片和链接,但我是新的,所以有限制

这是我视图中的代码:

 <%= 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

3 个答案:

答案 0 :(得分:1)

查看网页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> 

EDIT。来自Chrome的控制台

  

无法加载资源   http://localhost:3000/timeglider/css/aristo/jquery-ui-1.8.5.custom.cssFailed   加载资源   http://localhost:3000/timeglider/js/timeglider/Timeglider.cssFailed来   加载资源   应用a4d3485a82d7a76995c8b93a7477f17a.js:315Uncaught   ReferenceError:未定义jQuery   http://localhost:3000/timeglider/js/jquery.jsFailed加载资源   要加载http://localhost:3000/timeglider/js/jquery-ui.jsFailed   资源http://localhost:3000/timeglider/js/underscore-min.jsFailed   加载资源   要加载http://localhost:3000/timeglider/js/backbone-min.jsFailed   资源http://localhost:3000/timeglider/js/jquery.tmpl.jsFailed到   加载资源   要加载http://localhost:3000/timeglider/js/ba-debug.min.jsFailed   资源http://localhost:3000/timeglider/js/ba-tinyPubSub.jsFailed到   加载资源   http://localhost:3000/timeglider/js/jquery.mousewheel.min.jsFailed来   加载资源   要加载http://localhost:3000/timeglider/js/jquery.ui.ipad.jsFailed   资源http://localhost:3000/timeglider/js/raphael-min.jsFailed到   加载资源   要加载http://localhost:3000/timeglider/js/jquery.global.jsFailed   资源   http://localhost:3000/timeglider/js/timeglider/TG_Date.jsFailed来   加载资源   要加载http://localhost:3000/timeglider/js/timeglider/TG_Org.jsFailed   资源   http://localhost:3000/timeglider/js/timeglider/TG_Timeline.jsFailed来   加载资源   http://localhost:3000/timeglider/js/timeglider/TG_TimelineView.jsFailed   加载资源   http://localhost:3000/timeglider/js/timeglider/TG_Mediator.jsFailed来   加载资源   http://localhost:3000/timeglider/js/timeglider/timeglider.timeline.widget.jsFailed   加载资源   要加载http://geojiffy.herokuapp.com/assets/defaults.jsFailed   资源:服务器响应状态为404(未找到)   http://geojiffy.herokuapp.com/:149Uncaught ReferenceError:$不是   已定义http://geojiffy.herokuapp.com/:277Uncaught ReferenceError:   Gmaps未定义

答案 1 :(得分:1)

好的问题是初学者,谢谢大家的提示。线索来自jquery引用错误。在资产管道中加载脚本时,还必须注意加载的顺序。您可以在Asset Pipeline中看到类似的问题,但不是 jquery is not define error 这就是我的应用程序中的application.js中的良好顺序:

//= require jquery
//= require jquery-ui
//= require jquery_ujs
//= require jquery-1.7.1.min.js 
//= require jquery-ui-1.8.16.custom.min.js
//= require jiffies.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
//= require gmap3.min.js//= require jquery
//= require jquery-ui
//= require jquery_ujs
//= require jquery-1.7.1.min.js 
//= require jquery-ui-1.8.16.custom.min.js
//= require jiffies.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
//= require gmap3.min.js

你可以看到第一个jquery然后是jquery-ui,之后是dir gmaps4rails /中的所有api,最后是gmaps.min.js

同样//= require_tree .生产效果不错。您必须记下所需的所有脚本路径:// = require PATH_TO_THE_SCRIPT。

Merci

答案 2 :(得分:0)

这是完全逻辑:你的application.js文件没有加载,因为它们是一个错误“Uncaught ReferenceError:jQuery未定义”。

这就是为什么之后没有定义Gmaps的原因。修复你的js依赖。