From: Brian Candler Date: 2010-02-16T00:03:24+09:00 Subject: Re: Skipping headers in FasterCSV John Mcleod wrote: > Thanks Brian for the reply. > > I tried your advice and yes it does retrieve the row. > > Irb.transaction do > FasterCSV.parse(file, :headers => true) do |row| > puts "Row:" + row.fields(0,1,2,3,4,5).to_s > Irb.create(row.to_hash) > end > end > > I still get an error... > > "Error adding projects to IRB table. (unknown attribute: Q.1B PI8 Last). > Please try again." That's because you're still using row.to_hash and not row.fields !! Try something like this: Irb.create("foo" => row.field(0), "bar" => row.field(1), "baz" => row.field(2)) You should also be able to use row.fields without any args to get a flat array. f = row.fields Irb.create("foo"=>f[0], "bar"=>f[1], "baz"=>f[2]) > Also, if I just do this... > > Irb.transaction do > FasterCSV.parse(file, :headers => true) do |row| > puts "Row:" + row.to_s > Irb.create(row.to_hash) > end > end > > I get all row data with commas. So I am getting the row data without the > headers. Yes. row.to_s converts back to a CSV row. From the source: def to_csv(options = Hash.new) fields.to_csv(options) end alias_method :to_s, :to_csv -- Posted via http://www.ruby-forum.com/.