Вопрос

How do I create a link to the current Class object using gmaps4rails gem?

I have specified the info window in the model like so:

def gmaps4rails_infowindow
    "<h3>#{address}</h3>"
end

However I would like to create a link to the object's show page that appears in the info window e.g.:

def gmaps4rails_infowindow
    "#{link_to 'Object' , object_path}"
end

However because this is within the model I can't use _path or _url.

Is there a way to do this from the controller or another easy solution?

***Update

Controller:

@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

Infowindow view:

<%= link_to 'See Offer', @offer_path %>
Это было полезно?

Решение

Of course, read the doc here.

Here is the example provided when you work in your controller:

@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

I tend to put infowindow code in partials since its cleaner, but you're not compelled to use this abstraction.


I assume you use version < 2.x otherwise, the relevant doc is here and the method has changed.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top