Rails 4 gmaps4rails - How to include a show view link in the infowindow marker in gmaps4rails gem

I have gmaps4rails working in my rails 4 application with markers for my lcoation, and I would like to include a link in each location marker in each local separate show.

The index action of my space controller is as follows:

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 private infoindustry:

 <%= link_to "Show", space_path(space) %> 

My gmaps4rails javascript script in my /index.html space:

 <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 the space index page, I am greeted with the following error message:

 undefined local variable or method `space' for #<#<Class:0x4638c48>:0x5335f20> 

According to my previous requests, this seems to be a way to get the link acting in the index, but if there is an alternative solution, I would like to hear it, thanks.

+8
ruby-on-rails ruby-on-rails-4 google-maps gmaps4rails
source share
1 answer

Originally posted by OP in the question itself

The space controller index value should look 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 a partial view should look like this:

 <%= link_to 'See Space', space_path(object) %> 

+2
source share

All Articles