我不知道我错过了什么。我在另一篇文章中看到 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
application.html.erb 代码
<!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"}]