def zipcode=(new_zipcode)
if new_zipcode != self.zipcode
write_attribute(zipcode, new_zipcode) #problem here
#tries to geolocate with the zipcode then does the corresponding update
GeoKit::Geocoders::MultiGeocoder.geocode(new_zipcode).success? update_geolocation(loc) : nilify_geolocation
end
end
Refactorings
No refactoring yet !
Ben Burkert
November 28, 2007, November 28, 2007 03:23, permalink
the first argument of write_attribute should be a symbol or a string. In your example you are trying to write the new value of zipcode to a column with the same name as the old value of zip code.
def zipcode=(new_zipcode)
if new_zipcode != self.zipcode
write_attribute(:zipcode, new_zipcode) #problem here
#tries to geolocate with the zipcode then does the corresponding update
GeoKit::Geocoders::MultiGeocoder.geocode(new_zipcode).success? update_geolocation(loc) : nilify_geolocation
end
end
I simply want to overwrite the zipcode= attributes so that it only does the lookup on the geocoder if the zipcode changed.
All values are saved from the update_geolocation and nilify_geolocation operations but I am not able to save the new_zipcode. I have tried various tricks to prevent an endless loop and didnt manage do achieve anything good and elegant. I then tried the solution presented here which doesnt work either. Anyone has an idea?