ruby-on-rails – Rails 4 gmaps4rails – 如何在gmaps4rails gem中的标记infowindow中包含指向“show”视图的链接

我已经在我的rails 4应用程序中使用了gmaps4rails,我的lcoation有标记,我想在每个位置的标记中包含一个链接到每个位置的各个节目视图.

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

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

我的space / 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>

当我尝试加载我的空间索引页面时,我收到以下错误消息:

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

根据我之前的搜索,这似乎是让一个链接标记的infowindow中工作的方法,但如果有另一种解决方案,我很乐意听到它,谢谢.

解决方法

最初由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) %>

相关文章

validates:conclusion,:presence=>true,:inclusion=>{...
一、redis集群搭建redis3.0以前,提供了Sentinel工具来监控各...
分享一下我老师大神的人工智能教程。零基础!通俗易懂!风趣...
上一篇博文 ruby传参之引用类型 里边定义了一个方法名 mo...
一编程与编程语言 什么是编程语言? 能够被计算机所识别的表...
Ruby类和对象Ruby是一种完美的面向对象编程语言。面向对象编...