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