Saturday, January 12, 2008

Rails migration with a list of all United States

How many times have you created web applications that use addresses? Since I felt like I wasted the entire 10 minutes it took me to type out this state list, I figured I'd share it with everyone so that their time wasn't equally wasted. Enjoy.

Run this command:
ruby script/generate model State

And put this in db/migrate/XXX_create_states.rb:
class CreateStates < ActiveRecord::Migration
def self.up
create_table :states do |t|
t.column :name, :string
t.column :abbreviation, :string
end

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

end

def self.down
drop_table :states
end
end

5 comments:

  1. Yet another great case of "Ask google and you shall receive".

    Thanks for the state list :)

    ReplyDelete
  2. @kasey: Yeah, I guess running the command

    ruby script/generate model State

    would make more sense instead of just creating the migration. In other words, you do need a State model.

    ReplyDelete
  3. `'' I am really thankful to this topic because it really gives great information *;:

    ReplyDelete
  4. ;:: that seems to be a great topic, i really love it -.;

    ReplyDelete
  5. Slots are an incredibly popular form of playing since they are simple and easy to use, and often have giant jackpots to make the game more exciting. This site presents {a giant number of|numerous|a lot of} jackpot games, its largest being the progressive jackpot, Mega Moolah, which frequently presents jackpots into the hundreds 아벤카지노 of thousands of pounds. He most performed casino games are slot machines and table games.

    ReplyDelete