Skip to content

Instantly share code, notes, and snippets.

@ashaw ashaw/c4-import.rake Secret
Created Jun 19, 2012

Embed
What would you like to do?
task :import => :environment do
Organization.delete_all
f = FasterCSV.open("#{Rails.root.to_s}/db/initial/data.csv", :headers => true)
f.each do |row|
record = Organization.new
org = row.to_hash
org.each do |field, val|
next unless val
val = val.strip
if Organization.columns_hash[field].type == :integer
val = val.gsub(/[,\$]/,"").to_f
end
if Organization.columns_hash[field].type == :boolean
val = val.downcase =~ /(yes|x+)/ ? true : false
end
record[field] = val
end
p record
record.save
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.