I have an Address model which contains the fields: number, street, city, post_code
.
I use a method called fulladdress
to interpolate all the fields into one, which is then passed to geocoder which returns the Longitude and Latitude for the address.
Here is my Address model:
class Address < ActiveRecord::Base
belongs_to :user
def fulladdress
"#{number} #{street}, #{city}, #{post_code}"
end
geocoded_by :fulladdress
after_validation :geocode, :if => :number_changed?
end
At the moment, geocoder only updates the Long and Lat if number
has changed. What I want is for geocoder to run if any of number, street, city, post_code
change. What is the best practice way to do this?