Good morning,
I have a q related to a file-upload action that parses a .csv-file via FasterCSV: It works perfectly -once- (file is being uploaded & the data is being read, parsed and processed), but when I try doing it a second time (same .csv-file or a different one), it does not work - in the dev-/server-log it says that the file was uploaded, but nothing get's parsed. Here's the controller with the actions:
1 class Admin::GeneralController < ApplicationController 2 before_filter :login_required 3 4 def index 5 end 6 7 def import 8 end 9 10 def do_import 11 # ... 12 # requires FasterCSV gem 13 csv = params[:attachment][:file] 14 fehler = 15 rownumber = 0 16 if !csv.original_filename.empty? 17 FasterCSV.parse(csv) do |row| 18 if rownumber > 0 19 l = Lead.new(:vorname => row[1], 20 :nachname => row[0], 21 :strasse => row[2], 22 :plz => row[3].to_i, 23 :wohnort => row[4], 24 :beruf_branche => row[5], 25 :kommentar => "Berufsstand: " + row[6] + ", Familienstand: " + row[10] + ", Hoehe KT: " + row[11], 26 :telefon => row[8], 27 :email => row[9]) 28 r = l.save if l.valid? 29 if r 30 # erfolgreich importiert 31 else 32 # fehler-zeilen merken 33 fehler << row 34 end 35 end 36 rownumber = rownumber + 1 37 end 38 end 39 redirect_to :action => 'import' 40 end 41 end