Alex Rivera | Logout

Rails Select Drop Down for States?

Asked 2011-06-19T01:31:35.603
74

I was wondering if maybe there was some already built in function for rails so that it would create a select drop down list with all the U.S. states so I wouldn't have to enter it manually. I searched online but I was unable to find any. Any suggestions on what to do so I don't have to manually enter all the states?

Edit
Report

1 Answer

18

For this I typically use the Carmen and Carmen-Rails gems.

https://github.com/jim/carmen

https://github.com/jim/carmen-rails

Since my projects are still all on Ruby 1.8, I have to use the specific ruby-18 branch, so I have the following in my Gemfile:

gem 'carmen', :git => 'git://github.com/jim/carmen.git', :tag => 'ruby-18'
gem 'carmen-rails', :git => 'git://github.com/jim/carmen-rails.git'

Then, to create the select tag for all US states in a form where you're editing the :state_code field of an :address model object...

subregion_select(:address, :state_code, Carmen::Country.coded('US'))
answered 2012-12-19T19:04:25.650

Your Answer