apneadiving / Google-Maps-for-Rails

Enables easy Google map + overlays creation in Ruby apps
https://apneadiving.github.io/
MIT License
2.26k stars 382 forks source link

Accessing longitude, latitude from other model #267

Closed KieranLafferty closed 12 years ago

KieranLafferty commented 12 years ago

I have a db with the following set up:

Venue has_one location

Location contains latitude, longitude variables. I want to be able to set my Venue model to acts_as_gmappable and display them on the map as markers. I have tried setting the following :

belongs_to :location

acts_as_gmappable :lng=> "#{self.location.longitude}", :lng => "#{self.location.latitude}"

def gmaps4rails_address

describe how to retrieve the address from your model, if you use directly a db column, you can dry your code, see wiki

"#{self.location.street_address}, #{self.location.city}, #{self.location.country}" 

end

But get unknown attribute "location" when I try to run. Could you please advise whether this is possible?

KieranLafferty commented 12 years ago

Fixed it.. I created methods named 'latitude' and longitude and gmaps used those i.e

def latitude self.location.latitude end

def longitude self.location.longitude end