我想知道如何从我的模型中获取 ID 字段以传递我在单击标记时调用的 JavaScript。
我的模型:
acts_as_gmappable :process_geocoding => false, :lat => "lat", :lng => "lon"
我的控制器
def index
@locales_markers = Locale.all.to_gmaps4rails
respond_to do |format|
format.html { render :layout => false }
end
end
我的观点
<%= gmaps("markers" => { "data" => @locales_markers } %>
<% content_for :scripts do %>
<script>
Gmaps4Rails.callback = function() {
for (var i = 0; i < this.markers.length; ++i) {
google.maps.event.addListener(Gmaps4Rails.markers[i].serviceObject, 'click', function(){
$('#info').load('/messages/' **<HERE I'D LIKE TO PASS THE ID>**);
$('#info').dialog("open");
});
}
};
</script>
<% end %>
谢谢,卢西亚诺