我正在尝试学习 Rails,我想学习的第一个练习是自动将 csv 导入数据库。所以我通过使用创建了模型
rails g scaffold Domain dns:string current_bid:integer join_by_pt:datetime bidders:integer seller:string tld:string length:integer words:string categories:string hyphnens:string numbers:string auction_type:string
接下来我创建了 rake 文件:
require 'csv'
desc "Import domains from csv file"
task :import => [:environment] do
file = "db/dl.txt"
CSV.foreach(file, :headers => true) do |row|
entry = Domain.find_or_create_by(:dns => column[1])
entry.bid = column[2]
entry.join_date = DateTime.parse(column[3])
entry.bidders = column[4]
entry.seller = column[5]
entry.tld = column[6]
entry.length = column[7]
entry.words = column[8]
entry.categories = column[9]
entry.hyphens = column[10]
entry.numbers = column[11]
entry.auction_type = column[12]
entry.save
end
end
但是当我尝试运行它时,我得到了错误:
> rake aborted! undefined local variable or method `column' for
> main:Object /Users/user/drop/lib/tasks/import.rake:9:in `block (2
> levels) in <top (required)>'
> /Users/uer/drop/lib/tasks/import.rake:8:in `block in <top (required)>'
关于我做错了什么以及我的思路走向错误方向的任何指示?
谢谢