• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Importing a .csv file into mysql Ruby on Rails

 
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have tried to use Nokogiri just to grab all the data s i could go around saving it into an .csv file. However, I kept getting 503 errors so i had to work around it.

I have an excel file with rows   :name  :address  :phone  :image and i want to import this data into my preexisting database.



My preexisting table in ruby is



I saved my .csv file in my db folder and added import.rake to lib/tasks




when i run rake import i get



it gives this error for each of the rows I tried to import.
I am also worried that I'm doing this wrong and it will mess up my db so any advice would be appreciated.


 
Greenhorn
Posts: 6
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The issue is not in the CSV file. It is in your ruby code. You must add double braces around your `create` method like this:

Also, if you are worrying about the data in your database, then you should not be running this code in your production environment. As a test run, you can run this code in sandboxed rails console (`rails c -s`).
 
reply
    Bookmark Topic Watch Topic
  • New Topic