Sha256: db4cf89a97145c9e086851c90cf5a90cbf475689149f4380f5e3108fa1e2bae5

Contents?: true

Size: 722 Bytes

Versions: 7

Compression:

Stored size: 722 Bytes

Contents

require "countries"

class PopulateCountriesAndStates < ActiveRecord::Migration
  def up
    Piggybak::Country.class_eval do
      self.table_name = 'countries'
    end
    Piggybak::State.class_eval do
      self.table_name = 'states'
    end

    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|
        name = key
        abbr = value["name"]
        Piggybak::State.create! :name => name, :abbr => abbr, :country => country
      end
    end
  end

  def down
    # nothing here
  end
end

Version data entries

7 entries across 7 versions & 2 rubygems

Version Path
piggybak-0.7.6 db/migrate/20120104020930_populate_countries_and_states.rb
piggybak-0.7.5 db/migrate/20120104020930_populate_countries_and_states.rb
piggybak_free_shipping_by_product-0.0.2 test/dummy/db/migrate/20120104020930_populate_countries_and_states.rb
piggybak_free_shipping_by_product-0.0.1 test/dummy/db/migrate/20120104020930_populate_countries_and_states.rb
piggybak-0.7.4 db/migrate/20120104020930_populate_countries_and_states.rb
piggybak-0.7.3 db/migrate/20120104020930_populate_countries_and_states.rb
piggybak-0.7.2 db/migrate/20120104020930_populate_countries_and_states.rb