使用 google-maps-for-rails 效果很好!
我可以在标记信息窗口中使用(路由)url_path。
我现在使用此代码
def gmaps4rails_infowindow
"<a href='http://domainname/en/guide/umbrie/steden/#{slug}'>#{name} - #{city_h1} </a> <br><br>#{city_description} <br> <br> <img src='/assets/#{slug}.jpg'> "
end
但我想在同一张地图中显示另一个模型,所以不同的 url。我在方法中尝试了我的 url_path,但没有成功。我怎样才能做到这一点?
根据您的回复,我尝试了这个
控制器:
@json = City.all.to_gmaps4rails do |city, marker|
marker.infowindow render_to_string(:partial => "/cities/show", :locals => { :object => city })
marker.title "#{city.city_h1}"
marker.sidebar "#{city.name} - #{city.city_h1} "
marker.json({ :id => city.id, :name => city.name})
end
部分的:
%h1
= city.name
我收到此错误消息:
City Load (2.2ms) SELECT `cities`.* FROM `cities`
Rendered cities/_show.html.haml (28143.9ms)
Completed 500 Internal Server Error in 28230ms
ActionView::Template::Error (undefined local variable or method `city' for #<#<Class:0x007fcab6bf0f08>:0x007fcab6be1080>):
1: %h1
2: = city.name