Reputation: 1637
I have a rails for app with geocoder.
I'm important ical files so sometimes they have a lat/long already in the files, sometimes they don't.
How do I tell the model to geocode only if lat/long are not already present? And how do i tell geocoder to use those lat/long and trust them?
geocoded_by :full_address
after_validation :geocode, :if => :address1_changed?
Will geocoder just understand that I have the long/lat if i just set latitude and longitude directly?
Upvotes: 0
Views: 263
Reputation: 567
You can write a custom conditional.
after_validation :geocode, if: :address_changed_and_lat_long_blank?
private
def address_changed_and_lat_long_blank?
address1_changed? || lat.blank? || long.blank?
end
Hope this helps!
Upvotes: 2