Skip to content

Instantly share code, notes, and snippets.

@rgraff
Created June 23, 2009 16:13
Show Gist options
  • Save rgraff/134641 to your computer and use it in GitHub Desktop.
Save rgraff/134641 to your computer and use it in GitHub Desktop.
# In application_controller
def current_postal
@postal_code ||= PostalCode.find_first_valid_in_united_states(
[params[:postal_code], previous_postal_requests.last, postal_from_geoip, 90013],
:include=>:territory)
end
# In postal_code.rb
def self.find_first_valid(zip_codes_to_try, options = {})
zip_codes_to_try.each do |zip|
found = PostalCode.find_by_postal_code_and_country_name(zip,'United States', options)
return found if found
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment