upload file, read first 10 lines.

I have a csv file and in my controller:

uploaded_file = params[:upload][:csv].read @rows << FasterCSV.parse(uploaded_file)

I want to put in @rows only the first 10 lines but the read method reads all the file. How can I do?

I think you can do something like FasterCSV.foreach( uploaded_file) do |row|   # do something for first 10 rows then break out end

Colin

I have a csv file and in my controller:

uploaded_file = params[:upload][:csv].read @rows << FasterCSV.parse(uploaded_file)

I want to put in @rows only the first 10 lines but the read method reads all the file.

I think you can do something like FasterCSV.foreach( uploaded_file) do |row| # do something for first 10 rows then break out end

I've solved with:

uploaded_file = params[:upload][:csv].read     FasterCSV.parse(uploaded_file) do |row|       @rows[i] = row       i += 1       break row if i == 10     end