Archive

Archive for the ‘RubyGems’ Category

Import CSV Using Rails Migration

October 10, 2007 5 comments

Reposted from Rails Weenie:

Install FasterCSV (‘gem install fasterCSV’)

The code to use inside the migration is similar to:

FasterCSV.foreach(“#{RAILS_ROOT}/lib/symbols_database/security_list.csv“, :row_sep => “\r”) do |row|
field1,field2,field3 = row
Foo.create(:field1 => field1, :field2 => field2, :field3 => field3)
end

Categories: Ruby, RubyGems, Uncategorized