您好我正在尝试读取 csv 文件,我的代码是这样的:
CSV.foreach(path, {:col_sep => @seperator}) do |row|
#CSV.foreach(File.basename(path), {:col_sep => @seperator}) do |row|
r = Route.new
r.contact_id = contact_id
r.name = row[0]
r.number_range = row[1]
r.rate = row[3].gsub(",", ".").to_f
r.valid_from = DateTime.strptime(row[5], @time_format)
r.currency = @currency
r.save
end
我在这行有问题:
r.rate = row[3].gsub(",", ".").to_f
r.valid_from = DateTime.strptime(row[5], @time_format)
我得到错误:undefined method 'gsub' for nil:NilClass
和
undefined method `strptime' for nil:NilClass
但我完全确定 row[3] 和 row[5] 不是零,知道为什么会这样吗?提前致谢!