Ruby on rails Rails 4 gmaps4rails-如何包含指向;“显示”;在gmaps4rails gem的marker infowindow中查看

Ruby on rails Rails 4 gmaps4rails-如何包含指向;“显示”;在gmaps4rails gem的marker infowindow中查看,ruby-on-rails,google-maps,ruby-on-rails-4,gmaps4rails,Ruby On Rails,Google Maps,Ruby On Rails 4,Gmaps4rails,我已经让gmaps4rails在我的rails 4应用程序中运行,并为我的lcoation设置了标记,我想在每个位置的标记中包含一个指向每个位置的单个show view的链接 我的空间控制器索引操作如下所示: def index @spaces = Space.all @hash = Gmaps4rails.build_markers(@spaces) do |space, marker| marker.lat space.latitude marker.

我已经让gmaps4rails在我的rails 4应用程序中运行,并为我的lcoation设置了标记,我想在每个位置的标记中包含一个指向每个位置的单个show view的链接

我的空间控制器索引操作如下所示:

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) %>

我的spaces/index.html视图中的gmaps4rails javascript脚本是:

<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>

handler=Gmaps.build('Google');
buildMap({provider:{},internal:{id:'map'}},function(){
markers=handler.addMarkers();
handler.bounds.extendWith(markers);
handler.fitMapToBounds();
});
当我尝试加载我的共享空间索引页面时,会收到以下错误消息:

undefined local variable or method `space' for #<#<Class:0x4638c48>:0x5335f20>
未定义的局部变量或方法“space”#

根据我之前的搜索,这似乎是在标记器的信息窗口中获得链接的方法,但如果有其他解决方案,我很乐意听到,谢谢。

最初由OP在问题本身中发布。

空间控制器索引操作应如下所示:

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
局部视图应如下所示:

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



您可以将更新部分移出此问题的答案中,并接受您自己的问题。这样,你的问题就不会以未解决的形式出现,人们可以对你的答案进行投票,如果他们愿意的话!:)请不要在问题中加上答案;将您的解决方案张贴在下面的回答帖子中。我已将您的编辑从问题帖子中删除。如果您要这样做,最好将该帖子设置为社区wiki帖子,并添加一条注释,说明这是从OP的帖子中获取的。看见我现在已经转换了这篇文章。@MartijnPieters:非常感谢。