# Csv problem; help

**URL:** <https://www.ruby-forum.com/t/csv-problem-help/143212>\
**Category:** Rails\
**Created:** [July 16, 2008, 12:48pm UTC](https://www.ruby-forum.com/t/csv-problem-help/143212 "2008-07-16T12:48:07Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![kanekcwu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/7c8e57/32.png) [@kanekcwu](https://www.ruby-forum.com/u/kanekcwu)\
**Post date:** [July 16, 2008, 12:48pm UTC](https://www.ruby-forum.com/t/csv-problem-help/143212/1 "2008-07-16T12:48:07Z")

</div>

Hi, I am following the tutorial at

> **[How to import CSV file in rails](https://satishonrails.wordpress.com/2007/07/18/how-to-import-csv-file-in-rails/)**
>
> How to import CSV file in rails? The CSV text-file format is a common choice for both import and export when performing data migrations. What if you want to import CSV files within a Rails applicat…

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

---

<div class="post-metadata">

**Author:** ![kanekcwu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/7c8e57/32.png) [@kanekcwu](https://www.ruby-forum.com/u/kanekcwu)\
**Post date:** [July 16, 2008, 5:52pm UTC](https://www.ruby-forum.com/t/csv-problem-help/143212/2 "2008-07-16T17:52:05Z")

</div>

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…

---

<div class="post-metadata">

**Author:** ![kanekcwu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/7c8e57/32.png) [@kanekcwu](https://www.ruby-forum.com/u/kanekcwu)\
**Post date:** [July 17, 2008, 8:35am UTC](https://www.ruby-forum.com/t/csv-problem-help/143212/3 "2008-07-17T08:35:53Z")

</div>

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
