Created
November 8, 2013 21:35
-
-
Save kshsieh/7378060 to your computer and use it in GitHub Desktop.
city state country setting + validation proiblem
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# in a standard situation, params will be passed into a Coordinate object like below: | |
{ | |
city_input: "New York", | |
state_or_country_input: "NY", | |
latitude: "40.7143528", | |
longitude: "-74.0059731", | |
neighborhood: "Tyler Run-Queens Gate", | |
city: "New York", | |
state: "New York", | |
state_code: "NY", | |
sub_state: "York", | |
sub_state_code: "York", | |
country: "United States", | |
country_code: "US", | |
postal_code: "17403", | |
route: "New Fairview Church Road", | |
street_number: "1873", | |
street_address: "", | |
not_geocodable: 1 | |
} | |
# countries typically already exist in a populated db. states will often need to be created if international. so | |
# so a test environment is actually pretty ideal to test the creation and setting of these associated cities/states/countries | |
# city requires a state and country | |
# since state requires a country | |
# if a city has an existing state, then country is assumed to exist | |
# in a geocoding situation, setting country state and city in that order solve this problem | |
# but in something like a form, which will most likely pass params in order like above, | |
# city= state= country= is set in this order, which invalidates city and state if their associated locations don't necessarily exist | |
# so assuming the top down city, state, and country setting of these coordinate locationed associations | |
# city gets set first | |
# self here is a Coordinate object | |
if self.state | |
city_setter() # finds or creates a city with correct associations (state, country) and links it to a coordinate with city_id | |
else # state hasn't been set yet | |
# |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment