Skip to content

Instantly share code, notes, and snippets.

@quanon
Created June 15, 2012 02:31
Show Gist options
  • Save quanon/2934389 to your computer and use it in GitHub Desktop.
Save quanon/2934389 to your computer and use it in GitHub Desktop.
Import My CSV Data
require 'csv'
namespace :users do
desc 'Import users from a CSV file'
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