main:Object 的未定义局部变量或方法“类别”(NameError)

undefined local variable or method `category' for main:Object (NameError)

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

我收到如下错误:

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 文件加载到数据库中,但出现此错误..,请大家帮我解决这个问题。,

错误真的是你所需要的。您有一个尚未定义的变量类别。试试 'category'.

需要'csv' 加载 'dbconnection.rb' 需要 'activerecord'

class Definition<ActiveRecord::Base
end
CSV.foreach("C:/definition.csv") do |row|
Definition.create!(
    :category =>row[0],
    :name => row[1],
    :dangerlevel => row[2],
    :description => row[3]
    )
end