I have gotten gmaps4rails working in my rails 4 app, with markers for my lcoation, and I would like to include a link in each location's marker to each location's individual show view.
My spaces controller index action looks like this:
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
My infowindow partial is:
<%= link_to "Show", space_path(space) %>
My gmaps4rails javascript script in my spaces/index.html view is:
<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>
When I try to load my spaces index page I am greeted with the following error message:
undefined local variable or method `space' for #<#<Class:0x4638c48>:0x5335f20>
Based on my previous searches this seems to be the way to get a link working in a marker's infowindow but if there is an alternative solution I would love to hear it, thank you.
Originally posted by the OP in the question itself
spaces controller index action should looks like this :
def index
@spaces = Space.all
@hash = Gmaps4rails.build_markers(@spaces) do |space, marker|
marker.lat space.latitude
marker.lng space.longitude
marker.json({:id => space.id })
marker.infowindow render_to_string(:partial => "/spaces/infowindow", :locals => { :object => space})
end
end
and partial view should looks like this:
<%= link_to 'See Space', space_path(object) %>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With