# US State and their Respectives City

**URL:** <https://www.ruby-forum.com/t/us-state-and-their-respectives-city/175379>\
**Category:** Rails\
**Created:** [September 12, 2009, 6:18am UTC](https://www.ruby-forum.com/t/us-state-and-their-respectives-city/175379 "2009-09-12T06:18:50Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![salil](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/c89c15/32.png) [@salil](https://www.ruby-forum.com/u/salil)\
**Post date:** [September 12, 2009, 6:18am UTC](https://www.ruby-forum.com/t/us-state-and-their-respectives-city/175379/1 "2009-09-12T06:18:50Z")

</div>

Hello all!

I need to a implement a sign-up form with US states and city selector.  
Is there already a helper os something that  
implements or makes it easier to implement this for Rails.Also when i  
select the state all the city appears for that state in the other select  
list.

Btw, where could I get a list of US states and US cities? Is there  
any webservice for that ? Or just copy and paste from somewhere else?

Thanks in advance,

Salil G.

---

<div class="post-metadata">

**Author:** ![salil](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/c89c15/32.png) [@salil](https://www.ruby-forum.com/u/salil)\
**Post date:** [September 12, 2009, 9:09am UTC](https://www.ruby-forum.com/t/us-state-and-their-respectives-city/175379/2 "2009-09-12T09:09:24Z")

</div>

See if this helps !

> **[\#88 Dynamic Select Menus - RailsCasts](http://railscasts.com/episodes/88-dynamic-select-menus)**
>
> Short Ruby on Rails screencasts containing tips, tricks and tutorials. Great for both novice and experienced web developers.

Dave

On Sep 12, 12:18 pm, Salil G. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![salil](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/c89c15/32.png) [@salil](https://www.ruby-forum.com/u/salil)\
**Post date:** [September 13, 2009, 12:13am UTC](https://www.ruby-forum.com/t/us-state-and-their-respectives-city/175379/3 "2009-09-13T00:13:01Z")

</div>

On Sep 12, 12:18 am, Salil G. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> Hello all!
> 
> I need to a implement a sign-up form with US states and city selector.  
> Is there already a helper os something that  
> implements or makes it easier to implement this for Rails.Also when i  
> select the state all the city appears for that state in the other select  
> list.
> 
> Btw, where could I get a list of US states and US cities? Is there  
> any webservice for that ? Or just copy and paste from somewhere else?

Don’t do that - the select that you generate is going to be far too  
large to be practical. It’s hard to get a clear count of exactly how  
many cities are involved, but the best estimate I’ve seen places it  
somewhere around 20,000. An autocompleter might help, but you’ll still  
have the issue that city data can get stale (new ones are incorporated  
frequently). You’d be better served using a geocoder to verify that  
addresses actually match an existing DB (Google Maps, etc) and  
inquiring with the user if the address doesn’t match. Take a look at  
the GeoKit gem.

–Matt J.

---

<div class="post-metadata">

**Author:** ![salil](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/c89c15/32.png) [@salil](https://www.ruby-forum.com/u/salil)\
**Post date:** [September 14, 2009, 6:59pm UTC](https://www.ruby-forum.com/t/us-state-and-their-respectives-city/175379/4 "2009-09-14T18:59:43Z")

</div>

> FYI, to add some metrics here, I have a list of cities-in-states  
> that I  
> sourced from somewhere (US Census site, probably), and that list has  
> 55,324 entries.

I got my data from here. [U.S. 5 Digit ZIP Code Database List - Jun 1, 2023](http://www.zip-codes.com/zip-code-database.asp)  
The standard version has 29,778 non duplicate cities.

> So loading this into a select box, even dynamically,  
> seems problematic. As the previous poster suggested, use AJAX-based  
> autocomplete to keep the list of the server side instead.

+1.

---

<div class="post-metadata">

**Author:** ![salil](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/c89c15/32.png) [@salil](https://www.ruby-forum.com/u/salil)\
**Post date:** [September 14, 2009, 9:59pm UTC](https://www.ruby-forum.com/t/us-state-and-their-respectives-city/175379/5 "2009-09-14T21:59:05Z")

</div>

> I got my data from here. [U.S. 5 Digit ZIP Code Database List - Jun 1, 2023](http://www.zip-codes.com/zip-code-database.asp)  
> The standard version has 29,778 non duplicate cities.

Some ZIP codes cover multiple cities- i.e., 02573 is Martha’s Vineyard,  
Tisbury, and Vineyard Haven. So I think we’re talking apples and  
oranges here.

- D

---

<div class="post-metadata">

**Author:** ![salil](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/c89c15/32.png) [@salil](https://www.ruby-forum.com/u/salil)\
**Post date:** [September 13, 2009, 6:01am UTC](https://www.ruby-forum.com/t/us-state-and-their-respectives-city/175379/6 "2009-09-13T06:01:16Z")

</div>

FYI, to add some metrics here, I have a list of cities-in-states that I  
sourced from somewhere (US Census site, probably), and that list has  
55,324 entries. So loading this into a select box, even dynamically,  
seems problematic. As the previous poster suggested, use AJAX-based  
autocomplete to keep the list of the server side instead.

- D
