Hi, I am following the tutorial at http://satishonrails.wordpress.com/2007/07/18/how-to-import-csv-file-in-rails/ 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 [4;35;1mSQL (0.000000) [0m [0mBEGIN [0m [4;36;1mWinery Load (0.000000) [0m [0;1mSELECT * FROM `wineries` WHERE (wineries.name = ''Yalumba '') LIMIT 1 [0m [4;35;1mSQL (0.000000) [0m [0mCOMMIT [0m Any help would be apperciated thanks -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
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... --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Okay For my view I put in
<% form_for :dump, :url=>{:controller=>"wineries",
:action=>"csv_import"}, :html => { :multipart => true } do
|f| -%>
<table">
<tr>
<td>
<label for="dump_file">
Select a CSV File :
</label>
</td>
<td >
<%= f.file_field :file -%>
</td>
</tr>
<tr>
<td colspan=''2''>
<%= submit_tag ''Submit'' -%>
</td>
</tr>
</table>
<% 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/.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---