jeudi 30 juillet 2015

Ruby on Rails persistently store Hash from CSV

I have a ruby script written which takes a CSV file and converts the input into a hash:

Culper = File.open('.\CulperCSV.csv')

culper_hash = {}

# set up culper code hash from provided CSV
CSV.foreach(Culper) do |row|
    number, word = row
    culper_hash[word] = number
end

and I am trying to make a Rails app using the script.

My question: How do I store the Hash persistently (or the CSV data so I can build the hash) so that I can minimize load times?

My thoughts:

1) Load the CSV data into a database (seed it) and each time I get a visitor on my site, do the above assignment into a hash but from the db. (not sure how to do this but I can research it).

or

2) Load the complete hash into the database (I think I would have to serialize it?) so that I can do just one fetch from the db and have the hash ready to go.

I am very new to building apps, especially in Rails so please ask questions if what I am trying to do doesn't make sense.

Aucun commentaire:

Enregistrer un commentaire