Suppose I have a method that combines several address fields like so:
def address
"#{street_address}, #{city}, #{state}, #{postal_code}, #{country}"
end
How would I extend the method to allow for the checking if any of the fields have changed? Basically, I’d like to be able to do the following:
after_validation :geocode, :if => :address.changed?
My model is as follows:
class Place < ActiveRecord::Base
attr_accessible :street_address, :city, :state, :postal_code, :country, :latitude, :longitude, :geocode_type
geocoded_by :address
after_validation :geocode#, :if => :address.changed?
def address
"#{street_address}, #{city}, #{state}, #{postal_code}, #{country}"
end
end
Or is there a better way to do this all together?
1 Answer