Forums | Admin

Discussion Forums: help

Start New Thread Start New Thread

 

By: James Gray
RE: gem update and now I have a column name e [ reply ]  
2009-09-23 14:51
I'm glad to hear you sorted out your issue.

Just FYI, you can simplify this:

FCSV.new(file, :headers => true).each do |row|
# ...
end

to this:

FCSV.foreach(file, :headers => true) do |row|
# ...
end

Using foreach() is a little better since it will close the underlying IO object after you have seen all of the rows.

By: Demetrius Olsen
RE: gem update and now I have a column name error [ reply ]  
2009-09-23 05:31
Never mind :-) It turned out I had already imported that class. Need to create a new error message to let users know this :-)

By: Demetrius Olsen
gem update and now I have a column name error [ reply ]  
2009-09-23 05:15
I just updated FasterCSV and am getting the "Please verify that the column names in your CSV file are correct and try again" error. I noticed that there were a few header updates. Do I need to modify the code?

def csv_import
file = params[:csv_import][:file]
logcount=0

Student.transaction do
FCSV.new(file, :headers => true).each do |row|
current_user.students.create!(row.to_hash)
logcount += 1
end
end