我在ROR开发一个网站
我正在使用gem'gmaps4rails'。
在localhost中显示地图,但是当我放入生产服务器(DigitalOcean)时,会出现此错误:Uncaught ReferenceError: Gmaps is not defined
我在index.html.erb中有这个脚本:
<div id="map_show" ></div>
</div>
<script type="text/javascript">
handler = Gmaps.build('Google');
handler.buildMap({ provider: {}, internal: {id: 'map_show'}}, function(){
markers = handler.addMarkers(<%=raw @hash.to_json %>);
handler.bounds.extendWith(markers);
handler.fitMapToBounds();
});
</script>
我的application.js是这样的:
//= require jquery
//= require bootstrap-sprockets
//= require jquery_ujs
//= require turbolinks
//= require underscore
//= require gmaps/google
//= require highcharts
//= require chartkick
//= require_tree .
任何人都知道如何解决我的问题?
编辑1
Application.html.erb:
<!DOCTYPE html>
<html>
<head>
<title>ThomarWeb - Site espectacular de Turismo</title>
<%= csrf_meta_tags %>
<%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' %>
<%= javascript_include_tag 'application', 'data-turbolinks-track': 'reload' %>
<%= stylesheet_link_tag "gmaps4rails" %>
<%= javascript_include_tag "gmaps4rails" %>
<!--<script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyA4BHW3txEdqfxzdTlPwaHsYRSZbfeIcd8&callback=initMap"
async defer></script>-->
<script src="//maps.google.com/maps/api/js?key=AIzaSyA4BHW3txEdqfxzdTlPwaHsYRSZbfeIcd8"></script>
<script src="//cdn.rawgit.com/mahnunchik/markerclustererplus/master/dist/markerclusterer.min.js"></script>
<script src='//cdn.rawgit.com/printercu/google-maps-utility-library-v3-read-only/master/infobox/src/infobox_packed.js' type='text/javascript'></script> <!-- only if you need custom infoboxes -->
</head>
<body>
<%= render 'layouts/header' %>
<div class="container-fluid">
<% flash.each do |name, msg| %>
<%= content_tag(:div, msg, class: "alert alert-info") %>
<% end %>
<%= yield %>
</div>
</body>
</html>
我正在学习本教程:https://gorails.com/deploy/ubuntu/16.04#nginx-passenger
解决!
我解决了我的问题。 问题是服务器中的javascripts文件。
我需要使用CDN:
<script src='//cdn.jsdelivr.net/gmaps4rails/2.1.2/gmaps4rails.js'> </script>
<script src='//cdnjs.cloudflare.com/ajax/libs/underscore.js/1.8.3/underscore.js'> </script>