gmaps4rails - 使用数组中的多个值填充infowindow

时间:2014-01-14 02:39:31

标签: ruby ruby-on-rails-3 gmaps4rails

我正在使用gmaps4rails gem,我希望在下面的代码中为reclage数组中的所有值设置infowindow。

class RecipesController < ApplicationController
  include ApplicationHelper

  def index

  end

  def home
    @countries = Country.where user_id: current_user.id

    @hash = Gmaps4rails.build_markers(@countries) do |country, marker|

      recipes = country.recipes

      marker.lat country.latitude
      marker.lng country.longitude

      marker.infowindow # want to list recipes.each here

    end
  end
end

感谢任何帮助。

2 个答案:

答案 0 :(得分:1)

您可以在块中设置变量,如下所示:

    @ticket_properties = Array.new
    @ticket.properties.each do |property|
      @ticket_properties.push(property)
    end  

    @hash = Gmaps4rails.build_markers(@ticket_properties) do |ticket_prop, marker|
        concat_info_window = "#{ticket_prop.name}, #{ticket_prop.address}"
        marker.lat ticket_prop.latitude
        marker.lng ticket_prop.longitude
        marker.infowindow concat_info_window
    end

以下是我在自己的应用程序中所做的类似示例:

/wdtrue

如果有帮助,请告诉我。

答案 1 :(得分:0)

我想你可以试试这个:

# render the content to a html string, then pass it to the infowindow method
marker.infowindow render_to_string("recipes/marker_info", :locals => { :recipes => recipes}, :layout => false, :formats => :html)

# recipes/marker_info.html.erb
<ul>
  <% recipes.each do |recipe| %>
    <li><%= recipe.value # or other methods %></li>
  <% end %>
</ul>