Search code examples
ruby-on-railsrubygmaps4railsinfowindow

Displaying nested attributes at infowindow on gmaps4rails, resulting in #


I am making an applicattion that uses gmaps4rails gem which is a simple contact manager with mapping capabilities, so i have the main model by the name person which has

class Person < ActiveRecord::Base
attr_accessible :details, :gmaps, :latitude, :longitude, :address, :name,    :contacts_attributes
has_many :contacts
accepts_nested_attributes_for :contacts, allow_destroy: true

acts_as_gmappable

def gmaps4rails_address
  address
end

def gmaps4rails_infowindow
 "Name: #{name} <br \>
 #{details}
 //list with symbols of type of contact and contact by itself
 #{contacts. ??? }
 "
end

Where my contacts model has three attributes, the persons_id, type (be it email, phone, mobile) and Contact by itself, so how can i pass this to a list inside of infowindow?

Here is an image of how it displays

And btw, i defined this all in the model and not controller, since it was easier for me at the time...

Thank you in advance


Solution

  • Just reread, you could do:

    def gmaps4rails_infowindow
      text = "Name: #{name} <br/>"
      contacts.each do |contact|
        text << "#{contact.email}..."
      end
      text
    end