I am new to RoR, so there are many concepts that I don’t understand yet.
As my first project on rails, I coded the site base in a textbook by Michael Hartle. My site is made in rails 3.1.0 and it works fine in dev on my ubuntu station. Inside this site, I have gmaps4rails, which loads into gemfile like this:
gem 'gmaps4rails', "~> 1.4.8"
I have another control called timeglider, which is a javacript control that is located in my public folder in the / public / timeglider folder.
All this works in dev, but when I want to deploy this in production on heroku, I have a problem in my Chrome console:
http://geojiffy.herokuapp.com/:277Uncaught ReferenceError: Gmaps is not defined
http://geojiffy.herokuapp.com/:182Uncaught ReferenceError: Gmaps is not defined
I invite you to see the result of the loaded page here . There is nothing loaded in the gmaps section.
The problem is that gmaps is not detected when it reaches line # 277.
When I tried to fix this, I read many other questions in stackoverflow about sprocket and how to compile js file.
I changed application application.js from *= require_tree .to
//= 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
Scripts are compiled by heroku when creating a bullet
You can access the full application.js here.
You can find where the Gmaps object is defined in this script.
Clearly, there are many things that I don’t understand in rails, gmaps4rails and heroku that lead to the deployment problem. I'm not sure if the problem is with the asset pipeline.
, , . , ?
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;
$("#btn_change_geo").live('click', function() {
switchGeoChanging();
});
switchGeoChanging = function()
{
if (isGeoChanging)
{
$("#btn_change_geo").html("Change Jiffy Geo");
isGeoChanging = false;
$("#div_change_geo_info").hide();
}
else
{
$("#btn_change_geo").html("Cancel");
isGeoChanging = true;
$("#div_change_geo_info").show();
}
}
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()
{
if (lastGmapInfoWindowOpen != null) { lastGmapInfoWindowOpen.infowindow.close(); }
lastGmapInfoWindowOpen = marker;
if (lastTgInfoWindowOpen != null) { lastTgInfoWindowOpen.hide(); }
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."); }
});
}
$(".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