gmaps4rails重复标记的局部 [英] gmaps4rails repeating partials for markers

查看:73
本文介绍了gmaps4rails重复标记的局部的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使用gmaps4rails infowindow时遇到困难.我有一个应用程序,该应用程序使用存储在activerecord中的json数据成功显示了多个标记.我创建了一个局部视图,以选择其他信息以显示在信息窗口中,但是每个标记中都重复了PoliceAlert类的第一个实例的相同数据:

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:

控制器:

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的信息?提前谢谢你吗?

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

推荐答案

不确定理解,而是将您的局部替换为:

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 %>

这篇关于gmaps4rails重复标记的局部的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆