I have a simple Rails 3 app that uses Ruby Geocoder for a search form that my end users can use to determine their distance from other users of my app. I followed RailsCast episode #273 to implement it. However, sometimes when a new user is building his/her profile (which requires that they enter their zip code), the latitude & longitude columns of their record end up nil. In other words, their record is not being "geocoded." It seems to be pretty rare, but I'd like to determine a way to prevent this. Thanks!
Profile Model
class Profile < ActiveRecord::Base
attr_accessible :zip_code, :latitude, :longitude
geocoded_by :zip_code
after_validation :geocode, :if => :zip_code_changed?
VALID_ZIP_CODE_REGEX = /^\d{5}$/
validates :zip_code, presence: true, format: { with: VALID_ZIP_CODE_REGEX } # accepts 5-digit zip codes only
end
Aucun commentaire:
Enregistrer un commentaire