I'm having an issue with FasterCSV and my rake db:seeds migration. I get the error:
"rake aborted! Unquoted fields do not allow
or
(line 2)"
on the following seeds.rb data:
require 'csv'
directory = "db/init_data/"
file_name = "gardenzing020812.csv"
path_to_file = directory + file_name
puts 'Loading Plant records'
# Pre-load all Plant records
n=0
CSV.foreach(path_to_file) do |row|
Plant.create! :name => row[1],
:plant_type => row[3],
:group => row[2],
:image_path => row[45],
:height => row[5],
:sow_inside_outside => row[8]
n=n+1
end
I've searched for a solution to this problem and have discovered that for a lot of folks it's a UTF-8 encoding problem. I've tried requiring iconv and :encoding => 'u', but that then gives me the error "invalid byte sequence in UTF-8".
I'm a newbie, and I can't figure out if it's really an encoding issue that I need to crack (which I've been trying to do unsuccessfully and if so, I could really use some guidance) or, more likely I feel, that I've made a simple misstep and done something wrong with the way I've set up seeds.rb and possibly my excel -> csv file. There's no bad or awkward data in the csv file. It's simple one-word strings, text and integers. Please help!
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…