我对gmaps4rails infowindow有困难。我有一个应用程序,使用存储在activerecord中的json数据成功显示多个标记。我创建了一个部分来选择要在infowindow中显示的其他信息,但是在每个标记中重复了第一个PoliceAlert类实例的相同数据:
控制器:
class StaticPagesController < ApplicationController
def main
@police_alerts = PoliceAlert.all
@police_hash = Gmaps4rails.build_markers(@police_alerts) do |police_alert, marker|
marker.lat(police_alert.latitude)
marker.lng(police_alert.longitude)
marker.json({:id => police_alert.id })
marker.picture({
"url" => view_context.image_path('/assets/police.png'),
"width" => 32,
"height" => 37
})
marker.infowindow render_to_string(:partial => '/layouts/police_alerts_infowindow', :locals => { :police_alert => police_alert } )
end
end
部分:
<% PoliceAlert.find do |police_alert| %>
<%= police_alert.hundred_block_location %>
<br><%= police_alert.event_clearance_description %></br>
<%= police_alert.event_clearance_date %>
<% end %>
如何获取标记以显示每个police_alert的信息?非常感谢提前?
答案 0 :(得分:0)
不确定理解,但用以下内容替换你的部分:
<%= police_alert.hundred_block_location %>
<br/>
<%= police_alert.event_clearance_description %>
<br/>
<%= police_alert.event_clearance_date %>