Re: Csv problem; help

Kane Wu
2008-07-17T06:35:53Z

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
--
Posted via http://www.ruby-forum.com/.