ruby-on-rails – ActiveAdmin中的gmap4rails:不会出现地图

尝试在我的ActiveAdmin / Rails应用程序中使用gmaps4rails.为此,我在我的Gemfile中添加了以下内容:

gem 'gmaps4rails'

并运行了一个“捆绑”.我更新了app / admin / device.rb文件中的’show’方法:

show do 
  attributes_table do
    row :name
  end

  # Get device location
  @markers = Location.all.to_gmaps4rails
  div do
    render "map"
  end
end

在app / views / admin / devices / _map.html.erb中,我有以下代码:

<%= stylesheet_link_tag 'gmaps4rails' %>
<%= gmaps4rails(@markers) %>
<%= yield :scripts %>

在app / assets / javascripts / application.js中:

//= require gmaps4rails/gmaps4rails.googlemaps
//= require gmaps4rails/gmaps4rails.base
//= require jquery
//= require jquery_ujs
//= require_tree .

在我的app / models / location.rb中:

class Location < ActiveRecord::Base
  acts_as_gmappable

  attr_accessible :latitude, :longitude

  def gmaps4rails_address
    "#{self.latitude}, #{self.longitude}" 
  end

  def location
    [:latitude, :longitude]
  end
end

当我进入设备的显示页面时,地图不会显示(全部为空白).我错过了任何配置吗?

UPDATE

我已经使用chrome开发人员工具进行了检查,发现以下错误:

Uncaught SyntaxError: Unexpected token ;

引用该行:

Gmaps.map.markers = ;

最佳答案 修复以下内容:

div do
  markers = Location.all.to_gmaps4rails
  render "map", { :markers => markers }
end

并且:

<%= stylesheet_link_tag 'gmaps4rails' %>
<%= gmaps({
        "map_options" => { "zoom" => 2, "auto_adjust" => false},
        "markers"     => { "data" => markers }
        })
%>
<%= yield :scripts %>
点赞