Skip to content

Instantly share code, notes, and snippets.

@Erreon
Created January 23, 2010 07:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Erreon/284495 to your computer and use it in GitHub Desktop.
Save Erreon/284495 to your computer and use it in GitHub Desktop.
class Location < ActiveRecord::Base
attr_accessible :street_address, :city, :state, :zipcode, :price, :lat, :lng, :full_address
before_validation_on_create :geoleo
def geoleo
geo = Geokit::Geocoders::GoogleGeocoder.geocode(full_address)
errors.add(:full_address, "Could not Geocode address") if !geo.success
if geo.province == "Bexar"
self.street_address,self.city,self.state,self.county,self.lat, self.lng = geo.street_address,geo.city,geo.state,geo.province,geo.lat$
else
errors.add(full_address, "Address must be in Bexar County")
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment