DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snippets has posted 5883 posts at DZone. View Full User Profile

Hash Of US State Names And Abbreviations

11.23.2005
| 13295 views |
  • submit to reddit
        This is pretty handy, in a Rails view for example:

<b>View</b>

<select id="location_state" name="location[state]">
  <%= options_for_select( [[ "Select a State", "" ]] + State::NAMES )%>
</select>

<b>Model</b> (State.rb)

class State
  NAMES = [
    [ "Alabama", "AL" ], 
    [ "Alaska", "AK" ], 
    [ "Arizona", "AZ" ], 
    [ "Arkansas", "AR" ], 
    [ "California", "CA" ], 
    [ "Colorado", "CO" ], 
    [ "Connecticut", "CT" ], 
    [ "Delaware", "DE" ], 
    [ "District Of Columbia", "DC" ], 
    [ "Florida", "FL" ], 
    [ "Georgia", "GA" ], 
    [ "Hawaii", "HI" ], 
    [ "Idaho", "ID" ], 
    [ "Illinois", "IL" ], 
    [ "Indiana", "IN" ], 
    [ "Iowa", "IA" ], 
    [ "Kansas", "KS" ], 
    [ "Kentucky", "KY" ], 
    [ "Louisiana", "LA" ], 
    [ "Maine", "ME" ], 
    [ "Maryland", "MD" ], 
    [ "Massachusetts", "MA" ], 
    [ "Michigan", "MI" ], 
    [ "Minnesota", "MN" ], 
    [ "Mississippi", "MS" ], 
    [ "Missouri", "MO" ], 
    [ "Montana", "MT" ], 
    [ "Nebraska", "NE" ], 
    [ "Nevada", "NV" ], 
    [ "New Hampshire", "NH" ], 
    [ "New Jersey", "NJ" ], 
    [ "New Mexico", "NM" ], 
    [ "New York", "NY" ], 
    [ "North Carolina", "NC" ], 
    [ "North Dakota", "ND" ], 
    [ "Ohio", "OH" ], 
    [ "Oklahoma", "OK" ], 
    [ "Oregon", "OR" ], 
    [ "Pennsylvania", "PA" ], 
    [ "Rhode Island", "RI" ], 
    [ "South Carolina", "SC" ], 
    [ "South Dakota", "SD" ], 
    [ "Tennessee", "TN" ], 
    [ "Texas", "TX" ], 
    [ "Utah", "UT" ], 
    [ "Vermont", "VT" ], 
    [ "Virginia", "VA" ], 
    [ "Washington", "WA" ], 
    [ "West Virginia", "WV" ], 
    [ "Wisconsin", "WI" ], 
    [ "Wyoming", "WY" ]
  ]
end
    

Comments

Snippets Manager replied on Mon, 2012/05/07 - 2:16pm

Actually, the plugin installer is not dependent on SVN. Check out your ../rails-0.14.x/lib/commands/plugin.rb file for details, but suffice it to say that it will use HTTP.

Snippets Manager replied on Mon, 2012/05/07 - 2:16pm

Check out my us_states plugin: http://techno-weenie.net/svn/projects/plugins/us_states/ script/plugin discover # add techno-weenie.net script/plugin install us_states <%= us_state_options_for_select %> <%= us_state_select %>

Snippets Manager replied on Mon, 2012/05/07 - 2:16pm

Yeah plugins are great, but you can't use the plugin installer on stuff that is not under SVN. :-(