CSV upload button with validation

Hi all,

i urgently need help for my first RoR app which should be running
already. My app is a shop database (http://ewallshops.heroku.com/) made
with Heroku. Entering shops manually already works fine. Data entered is
checked for correctness of email adress and uniqueness of the shop name.

Now I need to add a button to enable front-end users to upload .csv shop
data that, during upload, also should pass the checks. In case of
errors, the data items containing them should be shown. The others
(without errors) shall be integrated into my database with continuing
ids (not those from the csv-file).

Some things about Heroku: As far as I know it uses Rails 2.0.2 and
postgresql as database.

Thanks in advance!
Daniel

Sorry to stress, but I really need help with this. I’ve already been
looking this forum and also tried several solutions, but none of them
worked. Please help me if you can. thx

How far have you gotten?

There are a few things you need to implement:

  1. Form which allows the user to upload the file (http://
    Peak Obsession)
  2. Controller method that imports the data

This method needs to iterate over each line, splitting the fields on
‘,’ and create the objects.
new_object = Object.new(blah, blah)

You store the failed objects in an array
failed << new_object unless new_object.save

  1. If failed contains entries you need to redirect to a form
    presenting the items to be corrected
    if failed.length > 0 redirect_to :action => ‘fix_records’

On Feb 26, 2:19 pm, Daniel B. [email protected]

Thanks for the hints, guys. At the moment I decided to go public without
the csv upload ability, because nothing I tried worked out well and I
have other projects that need my time. But when I have more time, I’ll
try to set it up like you told me. I’ll also try to implement the
loading bar feature described here:

which looks very promising (I tried to do that yesterday, but only got
mongrel errors). I’ll post again in case of success, so stay tuned if
you’re interested.

tip : u might want to use the valid? method of the model.

new_item = Item.new(:name=>…, bla bla)

failed_items = []

if new_item.valid?
… do something …
else
failed_items << new_item
end