gpt4 book ai didi

ruby-on-rails - ActiveAdmin : maps does not appear 中的 gmap4rails

转载 作者:行者123 更新时间:2023-12-04 07:36:15 24 4
gpt4 key购买 nike

尝试在我的 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

当我进入设备的显示页面时, map 不显示(全空白)。有没有我错过的配置?

更新

我已经检查了 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 %>

关于ruby-on-rails - ActiveAdmin : maps does not appear 中的 gmap4rails,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13780944/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com