rails 3: easiest way to load a large seed list (20,000 single words) into a table (using rake seed) on a Heroku app? -


on local dev machine have word list, 1 word per line, 20,000 words need load new table i'll call wordlist.

and need create exact same table on several heroku apps well, dont have local file storage.

the table schema id:integer , word:string

i've read numerous articles using seed.rb ... don't quite see how make work word list in file on dev machine, loading list table on local dev machine , on remote heroku app instances.

any ideas appreciated!

i take word list , stick in csv, 1 word on each line. should take 2 minutes. use fastercsv gem iterate through csv have saved in /lib/data. can stick /db/seeds.rb.

seeds.rb

fastercsv.foreach("#{rails_root}/lib/data/words.csv", :headers => :first_row) |row|   word.create_by_name(row[0]) end 

run rake db:seed , that's it. btw :headers => :first_row means skip first row if have title on top. if don't leave part out.

for remote file:

require 'open-uri' fastercsv.foreach(open("http://remotehost.com/words.csv"), :headers => :first_row) |row|   word.create_by_name(row[0]) end 

Comments

Popular posts from this blog

linux - Using a Cron Job to check if my mod_wsgi / apache server is running and restart -

actionscript 3 - TweenLite does not work with object -

jQuery Ajax Render Fragments OR Whole Page -