lib/tasks/china_regions.rake in china_regions-0.1.0 vs lib/tasks/china_regions.rake in china_regions-0.4.2

- old
+ new

@@ -7,42 +7,43 @@ task :import => :environment do file_path = File.join(Rails.root, 'config', 'cities.yml') data = File.open(file_path) { |file| YAML.load(file) } remove_china_regions && load_to_db(data) + puts "\n China's provinces, city, region data import is complete." end def remove_china_regions Province.delete_all && City.delete_all && District.delete_all end def load_to_db(data) data.each do |province_name, province_hash| province_parameters = province_params({ - name: province_name, - name_en: province_hash['name_en'], + name: province_name, + name_en: province_hash['name_en'], name_abbr: province_hash['name_abbr'] }) province = Province.create(province_parameters) province_hash['cities'].each do |city_name, city_hash| city_parameters = city_params({ province_id: province.id, - name: city_name, - name_en: city_hash['name_en'], - name_abbr: city_hash['name_abbr'], + name: city_name, + name_en: city_hash['name_en'], + name_abbr: city_hash['name_abbr'], zip_code: city_hash['zip_code'], level: city_hash['level'] || 4 }) city = City.create(city_parameters) districts_hash = city_hash['districts'] districts_hash.each do |district_name, district_hash| district_parameters = district_params({ city_id: city.id, - name: district_name, - name_en: district_hash['name_en'], + name: district_name, + name_en: district_hash['name_en'], name_abbr: district_hash['name_abbr'] }) District.create(district_parameters) end end