• 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 all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Tim Cooke
  • Paul Clapham
  • Devaka Cooray
  • Bear Bibeault
  • Junilu Lacar
  • Knute Snortum
  • Liutauras Vilda
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Piet Souris
  • salvin francis
  • Carey Brown
  • Frits Walraven

Importing a .csv file into mysql Ruby on Rails

Posts: 26
  • Mark post as helpful
  • send pies
  • 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.

Posts: 6
  • Likes 1
  • Mark post as helpful
  • send pies
  • 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`).
Let me tell you a story about a man named Jed. He made this tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
    Bookmark Topic Watch Topic
  • New Topic