Created
September 29, 2011 13:47
-
-
Save Marchino/1250754 to your computer and use it in GitHub Desktop.
import stuff from a csv with first row containing model's attributes
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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