0
require 'csv'
load 'dbconnection.rb'
require 'activerecord'
class Definition<ActiveRecord::Base
end
csv_definition = File.read('C:/definition.csv')
spy_definition = CSV.parse(csv_definition, :headers => false)
spy_definition.each do |row|
Definition.create!(
:id => row[id],
:category => row[category],
:name => row[name],
:dangerlevel => [dangerlevel],
:description => [description]
)
end
我正在一个错误,如下所示:未定义的局部变量或方法'分类”主:对象(NameError)
datainsertion.rb:26: warning: Object#id will be deprecated; use Object#object_id
datainsertion.rb:27: undefined local variable or method `category' for main:Object (NameError)
from datainsertion.rb:24:in `each'
from datainsertion.rb:24
>Exit code: 1
我需要加载该csv文件到数据库,但我得到这个错误..,帮助我们解决这个问题。,
我检查它也但它上升的误差作为 '[]':不能转换字符串into Integer(TypeError) – 2015-04-03 10:56:55
更多建议@Aristata – 2015-04-04 04:41:33