• Post Reply Bookmark Topic Watch Topic
  • New Topic

Importing a .csv file into mysql Ruby on Rails  RSS feed

 
Jeremiah Parrack
Greenhorn
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.


 
Uzbek Jon
Greenhorn
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`).
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!