Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Rails states selector for various countries and regions, including USA, Canada and Australia and more to come ...
Ruby
branch: master

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
lib
.gitignore
README.markdown
Rakefile
VERSION
init.rb

README.markdown

States select

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:

  • :usa
  • :canada
  • :australia
  • :india

:usa is the default region if either the :region or :locale option is not set (see usage below).

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.

Using locale files

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: This functionality has not yet been tested!

TODO

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?.

It would be nice to also have the option to use an autocomplete field instead of a selector. This gem could come in handy!

rails3 jquery autocomplete

I have started to add YAML support to the autocomplete here jquery autocomplete with yaml support

Install in Rails 3 app

In Gemfile

  gem 'states_select', '>= 1.0.1'

In console/terminal:

  $ 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)

Usage

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:

this (default):

<%= state_select 'child', 'state'%>   

will yield this:

  Alaska  

this:

  <%= state_select 'child', 'state', :show => :full %>   

will yield this:

  Alaska  

Options are:

:full = Alaska :full_abb = Alaska :abbreviations = AK :abb_full_abb = AK - Alaska

Something went wrong with that request. Please try again.