views:

30

answers:

1

I have a rails model called County that has 5 columns of data for different population attributes for that county. There is a record in the counties table for each county in the US. I now need to add additional county level data to meet a new need. The counties table will get an additional 10 or so rows for numeric population data (breakdown by race and ethnicity). I currently have the data in a .csv file, ready to go.

How do I seed the new data into the existing model such that I fill in the county specific information for each county in the database? Can this be done with rake db:seed?

+1  A: 

To start with, you can use FasterCSV to parse your input file. From there if you have a specific question please ask.

jdl
I would like to know how to handle this type of task most effectively. Should I just write a method in the model that I call to parse and loop through the .csv file and save each value into the proper field? Or is this something that can/should be handled through the `rake db:seed` task? I've done large seedings before using the rake task, but those were all with new models.
Clay
I would do it with a rake task, but not db:seed. Just a one-off custom task that loads in the new data. This is a one-time thing, right? It seemed that way from your question.
jdl
Yes, it is. Ok. Thanks... that's what I was looking for.
Clay