运行以下代码时出现此错误:
#!/usr/bin/env ruby -rubygems
require File.join(File.dirname(__FILE__), 'authentication')
require "csv" # faster_csv (ruby 1.9)
lines = CSV.read(File.join(File.dirname(__FILE__), 'karaoke.csv')) # Exported an Excel file as CSV
lines.slice!(0) # remove header line
collection = StorageRoom::Collection.find('collection ID')
Song = collection.entry_class
lines.each do |row|
karaoke = Song.new(:artist => row[0], :song => row[1], :genre => row[2], :file => StorageRoom::File.new_with_filename("#{karaoke.artist}#{karaoke.song}.mov"))
if karaoke.save
puts "Misuero Karaoke Latino saved: #{karaoke.artist}, #{karaoke.song}, #{karaoke.genre}"
else
puts "Misuero Karaoke Latino could not be saved: #{karaoke.errors.join(', ')}"
end
end
错误是:
import_csv.rb:15:in `block in <main>': undefined method `artist' for nil:NilClass (NoMethodError)
from import_csv.rb:14:in `each'
from import_csv.rb:14:in `<main>'
我有兴趣了解为什么会发生此错误以及解决方案。提前致谢!