我不知道我错过了什么。 我在另一篇文章中看到gmaps4rails gem包含一些处理json的javascripts代码,并且在我的页面呈现的代码中它没有出现。 地图的容器窗口是空白的,里面没有任何地图。 我正在运行rails 3.2.8,ruby 1.9.3和gmaps4rails 1.5.5。 提前谢谢。
respond_to :json, :html
def mostrar_mapa_unidades
@json = Unidade.all.to_gmaps4rails
respond_with @json
end
<%= gmaps4rails(@json) %>
<%= @json %>
acts_as_gmappable :process_geocoding => false
<!DOCTYPE html>
<html>
<head>
<title>SONep</title>
<%= stylesheet_link_tag :all %>
<%= javascript_include_tag :defaults %>
<%= csrf_meta_tag %>
</head>
<body>
<%= yield %>
<%= yield :scripts %>
</body>
</html>
<link href="/assets/gmaps4rails.css?body=1" media="screen" rel="stylesheet" type="text/css" />
<script src="/assets/jquery.js?body=1" type="text/javascript"></script>
<script src="/assets/jquery_ujs.js?body=1" type="text/javascript"></script>
<script src="/assets/gmaps4rails/gmaps4rails.base.js?body=1" type="text/javascript"></script>
<script src="/assets/gmaps4rails/gmaps4rails.bing.js?body=1" type="text/javascript"></script>
<script src="/assets/gmaps4rails/gmaps4rails.googlemaps.js?body=1" type="text/javascript"></script>
<script src="/assets/gmaps4rails/gmaps4rails.mapquest.js?body=1" type="text/javascript"></script>
<script src="/assets/gmaps4rails/gmaps4rails.openlayers.js?body=1" type="text/javascript"></script>
<div class="map_container">
<div id="map" class="gmaps4rails_map"></div>
</div>
@json
[{"lat":"-23.701613","lng":"-46.547077"},{"lat":"-23.704757","lng":"-46.545274"},{"lat":"-23.7074712","lng":"-46.5419723"}]