Skip to content

Instantly share code, notes, and snippets.

@Marchino
Created September 29, 2011 13:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Marchino/1250754 to your computer and use it in GitHub Desktop.
Save Marchino/1250754 to your computer and use it in GitHub Desktop.
import stuff from a csv with first row containing model's attributes
keys = []
CSV.foreach("/path/to/stuff/to/import.csv") do |row|
keys = row and first = false if first
ModelName.create(Hash[*keys.each{|k| k.strip!}.zip(row.each{|k| k.strip!}).flatten]) unless first
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment