Skip to content

Instantly share code, notes, and snippets.

@vltsu
Created June 24, 2012 21:22
Show Gist options
  • Save vltsu/2985053 to your computer and use it in GitHub Desktop.
Save vltsu/2985053 to your computer and use it in GitHub Desktop.
import from a CSV file
require 'csv'
namespace :users do
desc "Import users from csv"
task :import => :environment do
path = ENV.fetch("CSV_FILE") {
File.join(File.dirname(__FILE__), *%w[.. .. db data users.csv])
}
CSV.foreach(path, headers: true, header_converters: :symbol) do |row|
User.create(row.to_hash)
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment