require 'csv' desc "Populate ZipCode table with zipcodes from CSV file" namespace "db" do namespace "locateable" do task :populate_zipcodes => :environment do zip_code_data = File.expand_path(File.join(RAILS_ROOT, 'vendor/plugins/acts_as_locateable/data/zip_code_data.csv')) puts "Now importing about 45,000 zip codes from the free data set at http://www.cfdynamics.com/zipbase/." puts "This will probably take 5-10 minutes... " puts "[NOTE: if you want it to go faster, import the file\n #{zip_code_data} using your database's CSV import mechanism.]" CSV.open(zip_code_data, "r") do |row| ZipCode.create!(:zip => row[0], :latitude => row[1], :longitude => row[2], :city => row[3], :state => row[4], :zip_class => row[5]) end end end end