Csv problem; help

Hi, I am following the tutorial at


which teaches ppl how to import csv files. The problem though is that
when I try to run the code rails upload the information but is not
saving it into the database or making it into an object.

For what is on my console i just get 67 rows of this
e[4;35;1mSQL (0.000000)e[0m e[0mBEGINe[0m
e[4;36;1mWinery Load (0.000000)e[0m e[0;1mSELECT * FROM wineries
WHERE (wineries.name = 'Yalumba ') LIMIT 1e[0m
e[4;35;1mSQL (0.000000)e[0m e[0mCOMMITe[0m

Any help would be apperciated thanks

It would help a lot if you would post your code
and other information that may be related to this error.

The link you posted has nothing to do with a table “wineries”
and it looks quite like normal csv code, so it would work
if you would have used it correct…

Okay For my view I put in
<% form_for :dump, :url=>{:controller=>“wineries”,
:action=>“csv_import”}, :html => { :multipart => true } do |f| -%>
<table">

Select a CSV File : <%= f.file_field :file -%> <%= submit_tag 'Submit' -%> <% end -%>

while for my controller i have

def csv_import
@parsed_file=CSV::Reader.parse(params[:dump][:file])
debugger
n=0
@parsed_file.each do |row|
@Winery=Winery.new
@Winery.name=row[1]
@Winery.country=row[2]
@Winery.speciality=row[3]
@Winery.history=row[4]
@Winery.created_at=row[5]
@Winery.updated_at=row[67]
@Winery.region=row[7]
if @Winery.save
n=n+1
GC.start if n%50==0
end
flash.now[:message]=“CSV Import Successful, #{n} new records added
to data base”
end
end

When I use phpmyadmin I am able to upload the csv file but the problem
with that is it doesn’t create the object if I just use phpmyadmin.
Thanks

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