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.

Was it helpful?

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.

OTHER TIPS

try with this

location.address = location.reverse_geocode
location.save!
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top