我已經在我的rails 4應用程序中使用了gmaps4rails,併爲我的lcoation添加了標記,並且我希望在每個位置的標記都顯示在每個位置的個別顯示視圖中。Rails 4 gmaps4rails - 如何在gmaps4rails中的標記infowindow中包含指向「show」視圖的鏈接gem
我的空間控制指標的行動看起來是這樣的:
def index
@spaces = Space.all
@hash = Gmaps4rails.build_markers(@spaces) do |space, marker|
marker.lat space.latitude
marker.lng space.longitude
marker.infowindow render_to_string(:partial => "/spaces/infowindow", :locals => { :object=> space})
end
end
我的信息窗口的部分是:
<%= link_to "Show", space_path(space) %>
我gmaps4rails在我空間的javascript腳本/ index.html的觀點是:
<script>
handler = Gmaps.build('Google');
handler.buildMap({ provider: {}, internal: {id: 'map'}}, function(){
markers = handler.addMarkers(<%=raw @hash.to_json %>);
handler.bounds.extendWith(markers);
handler.fitMapToBounds();
});
</script>
當我嘗試加載空間索引頁面時,我收到以下錯誤消息:
undefined local variable or method `space' for #<#<Class:0x4638c48>:0x5335f20>
根據我以前的搜索,這似乎是得到一個鏈接標記的信息窗口工作的方式,但如果有一個替代的解決方案我很想聽到它,謝謝。
您可以將UPDATE部分移出到答案中回答這個問題並接受你自己的問題。通過這種方式,您的問題不會像未解決的問題那樣彈出,如果他們喜歡,人們可以對您的答案滿意! :) – zhurora
請不要在問題中回答問題;相反,請將您的解決方案作爲答案帖子發佈。我已經從問題文章中刪除了您的修改。 –