Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/63.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails gmaps4rails信息窗口(ruby/rails)_Ruby On Rails_Ruby_Gmaps4rails - Fatal编程技术网

Ruby on rails gmaps4rails信息窗口(ruby/rails)

Ruby on rails gmaps4rails信息窗口(ruby/rails),ruby-on-rails,ruby,gmaps4rails,Ruby On Rails,Ruby,Gmaps4rails,如何使用gmaps4rails gem创建指向当前类对象的链接 我在模型中指定了如下信息窗口: def gmaps4rails_infowindow "<h3>#{address}</h3>" end 但是,因为这是在模型中,所以我不能使用_path或_url 有没有办法从控制器或其他简单的解决方案中实现这一点 ***更新 控制器: @json = Offer.where('state = ?', 'new').all.to_gmaps4rails do |o

如何使用gmaps4rails gem创建指向当前类对象的链接

我在模型中指定了如下信息窗口:

def gmaps4rails_infowindow
    "<h3>#{address}</h3>"
end
但是,因为这是在模型中,所以我不能使用_path或_url

有没有办法从控制器或其他简单的解决方案中实现这一点

***更新

控制器:

@json = Offer.where('state = ?', 'new').all.to_gmaps4rails  do |offer, marker|
      marker.infowindow render_to_string(:partial => "offers/infowindow", :locals => { :object => offer})
      marker.picture({
                         #:picture => "http://www.blankdots.com/img/github-32x32.png",
                         :width   => 32,
                         :height  => 32
                     })
      marker.title   "i'm the title"
      marker.sidebar "i'm the sidebar"
      marker.json({ :id => offer.id, :address => offer.address})
    end
信息窗口视图:

<%= link_to 'See Offer', @offer_path %>

当然

以下是在控制器中工作时提供的示例:

@json = User.all.to_gmaps4rails do |user, marker|
  marker.infowindow render_to_string(:partial => "/users/my_template", :locals => { :object => user})
  marker.picture({
              :picture => "http://www.blankdots.com/img/github-32x32.png",
              :width   => 32,
              :height  => 32
             })
  marker.title   "i'm the title"
  marker.sidebar "i'm the sidebar"
  marker.json({ :id => user.id, :foo => "bar" })
end
我倾向于将infowindow代码放在片段中,因为它更干净,但您不必使用这种抽象



我假设您使用的是<2.x版本,否则,e和方法已经更改

非常感谢。这基本上是可行的,我现在只有一个问题-我创建的链接没有链接到show视图,而是呈现索引。我不明白为什么-你有什么建议吗?请参阅更新。这超出了问题范围。。。但是试试
@json = User.all.to_gmaps4rails do |user, marker|
  marker.infowindow render_to_string(:partial => "/users/my_template", :locals => { :object => user})
  marker.picture({
              :picture => "http://www.blankdots.com/img/github-32x32.png",
              :width   => 32,
              :height  => 32
             })
  marker.title   "i'm the title"
  marker.sidebar "i'm the sidebar"
  marker.json({ :id => user.id, :foo => "bar" })
end