Based on us_states plugin by techno-weenie
This project has been extended to be available as either a plugin or a gem and is now targeting Rails 3. The states selection has been made more flexible in order to support multiple countries and regions in the world (USA, Canada, ...). The select tag now takes a new :region option which currently supports the following:
Note: :usa is the default region if the :region option is not set.
Please help provide states for other regions/countries, fx EU, Africa, South America, ...
Note: 22 Dec. 2010
Currently this is mainly proof of concept and has not been fully tested. Guiney pigs wanted! Following up on a suggestion by asanghi, I have added a generator to copy yml locale files for one or more "locales" (usa, canada, australia). The gem now needs to be updated with an option to use these locale files instead of the hardcoded class methods.
To use the locale files use the :locale option instead of the region.
<%= state_select 'child', 'state', :locale => :usa %>
You can even provide different locale translations and use the :lang option. The following example should use the Chinese locale file of states for USA.
<%= state_select 'child', 'state', :locale => :usa, :lang => 'cn' %>
PS: Has not yet been tested!
Add RSpec 2 tests, including use of generator-spec to test the generator and rspec-action_view to test the view helpers with various Form builders?.
Install in Rails 3 app
gem 'states_select', '>= 1.0.1'
$ bundle install
Install as system gem
$ gem install states_select
Install as plugin
$ rails install plugin http://github.com/kristianmandrup/states_select.git
Or something like that... (i.e install as gem is recommended)
To select "priority" states that show up at the top of the list, call like so:
<%= state_select 'child', 'state', :priority => %w(TX CA) %> <%= state_select 'child', 'state', :priority => %w(ON), :country => :canada %>
To select the way states display option and value:
<%= state_select 'child', 'state'%>
will yield this:
<%= state_select 'child', 'state', :show => :full %>
will yield this:
:full = Alaska :full_abb = Alaska :abbreviations = AK :abb_full_abb = AK - Alaska