Search code examples
ruby-on-railscsvfastercsv

FasterCSV Parsing issue?


G'day guys, I'm currently using fastercsv to construct ActiveRecord elements and I can't for the life of me see this bug (tired), but for some reason when it creates, if in the rake file i output the column I want to save as the element value, it puts out correctly, as either a Trade or a Quote

but when I try to save it into the activerecord, it won't work.

FasterCSV.foreach("input.csv", :headers => true) do |row|
  d =  DateTime.parse(row[1]+" "+row[2])
  offset = Rational(row[3].to_i,24)
  o = d.new_offset(offset)
  t = Trade.create(
  :name => row[0],
  :type => row[4],
  :time => o,
  :price => row[6].to_f,
  :volume => row[7].to_i,
  :bidprice => row[10].to_f,
  :bidsize => row[11].to_i,
  :askprice => row[14].to_f,
  :asksize => row[15].to_i
  )
end

Ideas?

Name and Type are both strings, every other value works except for type. Have I missed something really simple?


Solution

  • Ruby's Object class has a type method. You need to t[:type] = row[4] to avoid that method.

    -Tim