Ignore first line on csv parse Rails

Posted by Jack on Stack Overflow See other posts from Stack Overflow or by Jack
Published on 2010-05-12T12:20:56Z Indexed on 2010/05/12 12:24 UTC
Read the original article Hit count: 192

Filed under:
|

Hi,

I am using the code from this tutorial to parse a CSV file and add the contents to a database table. How would I ignore the first line of the CSV file? The controller code is below:

def csv_import 
  @parsed_file=CSV::Reader.parse(params[:dump][:file])
  n = 0
  @parsed_file.each  do |row|
    s = Student.new
    s.name = row[0]
    s.cid = row[1]
    s.year_id = find_year_id_from_year_title(row[2])
    if s.save
      n = n+1
      GC.start if n%50==0
    end
    flash.now[:message] = "CSV Import Successful, #{n} new students added to the database."
  end
  redirect_to(students_url)
end

© Stack Overflow or respective owner

Related posts about csv

Related posts about ruby-on-rails