Created
February 4, 2014 19:05
-
-
Save bluerogue251/8810153 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace :db do | |
desc 'Move data from the carmen gem into the database' | |
task load_geo_data: :environment do | |
puts '-----------About to load geo-data from Carmen gem into the database----------------' | |
Carmen::Country.all.each do |country| | |
new_country = Country.create(name: country.name) | |
country.subregions.each do |subregion| | |
new_subregion = Subregion.create(country: new_country, name: subregion.name) | |
subregion.subregions.each do |city| | |
new_city = City.create(subregion: new_subregion, name: city.name) | |
end | |
end | |
end | |
puts '---------About to add extra city data--------------------------------------------' | |
city_data = [ | |
["China", "Anhui", "Hefei", 2.5, 125.00], | |
["China", "Fujian", "Fuzhou", 1.5, 65.00], | |
["China", "Fujian", "Xiamen", 3, 85.00], | |
["China", "Fujian", "Zhangzhou", 3, 95.00], | |
] | |
city_data.each do |country_name, subregion_name, city_name, estimated_travel_time, estimated_expenses| | |
city = City.find_by!(country_name: country_name, subregion_name: subregion_name, name: city_name) | |
city.update_attributes(estimated_travel_time: estimated_travel_time, estimated_expenses: estimated_expenses) | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment