Question

Why wouldn't

Location.where(address: nil).each do |location|
    location.reverse_geocode
    location.save!
end

work, while

class Location < ActiveRecord::Base
    reverse_geocoded_by :latitude, :longitude
    after_validation :reverse_geocode
end

reverse geocodes any new locations? The console doesn't error, it just returns the activerecord relation with the address values still nil.

Était-ce utile?

La solution 2

So my original solution worked, I just had to restart my machine. Strangely, restarting the console, server, and editor did nothing, so I suspect some dark magic is going on with RVM.

Thanks for the help, everyone.

Autres conseils

try with this

location.address = location.reverse_geocode
location.save!
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top