Sha256: e019221cc9edb7b9d3607eaca376f098e2be707d26f95b38ff2abbc1e561d3b7

Contents?: true

Size: 532 Bytes

Versions: 88

Compression:

Stored size: 532 Bytes

Contents

require "countries"

class PopulateCountriesAndStates < ActiveRecord::Migration
  def change
    ISO3166::Country.all.each do |country_array|
      name = country_array[0]
      abbr = country_array[1]
      country = Piggybak::Country.create :name => name, :abbr => abbr

      iso3166_country = ISO3166::Country.new(abbr)
      iso3166_country.states.each do |key, value|
        abbr = key
        name = value["name"]
        Piggybak::State.create! :name => name, :abbr => abbr, :country => country
      end
    end
  end
end

Version data entries

88 entries across 88 versions & 1 rubygems

Version Path
piggybak-0.5.1 db/migrate/20120104020930_populate_countries_and_states.rb
piggybak-0.5.0 db/migrate/20120104020930_populate_countries_and_states.rb
piggybak-0.4.39 db/migrate/20120104020930_populate_countries_and_states.rb
piggybak-0.4.38 db/migrate/20120104020930_populate_countries_and_states.rb
piggybak-0.4.37 db/migrate/20120104020930_populate_countries_and_states.rb
piggybak-0.4.36 db/migrate/20120104020930_populate_countries_and_states.rb
piggybak-0.4.35 db/migrate/20120104020930_populate_countries_and_states.rb
piggybak-0.4.34 db/migrate/20120104020930_populate_countries_and_states.rb
piggybak-0.4.33 db/migrate/20120104020930_populate_countries_and_states.rb
piggybak-0.4.32 db/migrate/20120104020930_populate_countries_and_states.rb
piggybak-0.4.31 db/migrate/20120104020930_populate_countries_and_states.rb
piggybak-0.4.30 db/migrate/20120104020930_populate_countries_and_states.rb
piggybak-0.4.29 db/migrate/20120104020930_populate_countries_and_states.rb
piggybak-0.4.28 db/migrate/20120104020930_populate_countries_and_states.rb
piggybak-0.4.27 db/migrate/20120104020930_populate_countries_and_states.rb
piggybak-0.4.26 db/migrate/20120104020930_populate_countries_and_states.rb
piggybak-0.4.25 db/migrate/20120104020930_populate_countries_and_states.rb
piggybak-0.4.24 db/migrate/20120104020930_populate_countries_and_states.rb
piggybak-0.4.23 db/migrate/20120104020930_populate_countries_and_states.rb
piggybak-0.4.22 db/migrate/20120104020930_populate_countries_and_states.rb