FasterCSV 解析问题?

发布于 2024-08-29 17:30:43 字数 678 浏览 4 评论 0原文

大家好,我目前正在使用 fastcsv 来构造 ActiveRecord 元素,我一生都看不到这个错误(累了),但由于某种原因,当它创建时,如果在 rake 文件中我输出列 I想要保存为元素值,它会正确输出,作为交易或报价,

但当我尝试将其保存到活动记录中时,它不起作用。

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

有想法吗?

名称和类型都是字符串,除了类型之外,所有其他值都有效。我错过了一些非常简单的事情吗?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

乞讨 2024-09-05 17:30:43

Ruby 的 Object 类有一个类型方法。您需要 t[:type] = row[4] 来避免该方法。

-蒂姆

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

-Tim

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文