gmaps4rails repeating partials for markers

拟墨画扇 提交于 2019-12-11 17:54:10

问题


I am having difficulty with gmaps4rails infowindow. I have an app which successfully displays multiple markers using json data stored in activerecord. I created a partial to select additional info to display in the infowindow, but the same data from the first instance of PoliceAlert class is being repeated in each marker:

Controller:

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

Partial:

<% PoliceAlert.find do |police_alert| %>
<%= police_alert.hundred_block_location %>
<br><%= police_alert.event_clearance_description %></br>
<%= police_alert.event_clearance_date %>
<% end %>

How do I get markers to display info for each police_alert? Thanks so much in advance?


回答1:


Not sure to understand but replace your partial with:

<%= police_alert.hundred_block_location %>
<br/>
<%= police_alert.event_clearance_description %>
<br/>
<%= police_alert.event_clearance_date %>


来源:https://stackoverflow.com/questions/23121060/gmaps4rails-repeating-partials-for-markers

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!