I'm using gmaps4rails awesome gem in my current project and have to import more than a thousand objects in the DB that should act as gmappable.
However not all of them have correct addresses! So when I try to import it fails on the first address that could not be geocoded with Gmaps4rails::GeocodeStatus.
Is it possible to skip errors and geocode where possible?
I came up with this:
acts_as_gmappable :process_geocoding => false
before_save :prepare_gmaps
private
def prepare_gmaps
begin
data = Gmaps4rails.geocode(address).first
self.latitude= data[:lat]
self.longitude= data[:lng]
rescue Gmaps4rails::GeocodeStatus
end
end
Did you simply try:
acts_as_gmappable :validation => false