Skip to content

asanghi/states_select

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

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.

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

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

About

Rails states selector for various countries and regions, including USA, Canada and Australia and more to come ...

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Ruby 100.0%