Search code examples
ruby-on-railsrubyruby-on-rails-3google-mapsgmaps4rails

How to use @marker data from two different models?


I have two models: One which contains :city_name, :long, :lat and the other :person_name, :occupation.

How do i create the @marker array using all data from those two different models?

I have managed to put the markers using long,lat,city_name but I fail to figure out how to add the rest...

Thanks,

Petros


Solution

  • Array is monkey patched in the gem so you can do:

    [].to_gmaps4rails
    

    Whatever the content of the array.

    So, simply build an Array with all data required.


    EDIT1: You can set the address of one model exactly the way you want:

    #Person model
    def gmaps4rails_address
      self.cities.first.whatever_relevant_column
    end
    

    But you can only have one address to take into account. Maybe a gem extension could be to take arrays as argument here.


    EDIT2:

    If you don't need geocoding, so you don't need to add the gmaps4rails_adress method.

    Simply add the acts_as_gmappable with your options (custom lat and lng in your case).