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
デバイスの表示ページに移動すると、マップが表示されません(すべて空白)。見逃した設定はありますか?
アップデート
Chrome開発ツールで確認したところ、次のエラーに気づきました。
Uncaught SyntaxError: Unexpected token ;
次の行を参照します。
Gmaps.map.markers = ;