File Uploads & parsing only work once?

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

and the import.rhtml / view looks like this:

1

Leads importieren


2

Bitte waehlen Sie eine .csv-Datei aus um die darin
enthaltenen
Leads zu importieren.


3
4 <%= start_form_tag({:action => ‘do_import’}, :multipart =>
true) %>
5 <%= file_field “attachment”, “file” %> <%= submit_tag “Save” %>
6 <%= end_form_tag %>

Any ideas why this is happening or what I did wrong?

Best regards & thanks,
-Joerg

Any ideas why this is happening or what I did wrong?

Best regards & thanks,
-Joerg

Dude, your code is written in German!!! Even if it was written in
English,
folks on this list don’t usually respond to this kind of question. I
have
had similar experience. Instead of posting all your code, you may want
to be
more specific to get response from Rails gurus.

Yeah you’re right - but the german parts are only the static parts. The
code is still in ruby/rails :wink:

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs