Skip to content Skip to sidebar Skip to footer

Ruby On Rails - Storing And Accessing Large Data Sets

I am having a hard time managing the storage and access of a large dataset within a Ruby on Rails application. Here is my application in a nutshell: I am performing Dijkstra's alg

Solution 1:

You're on the right path. There are a couple of ways to do this. One is, in your model class, outside of any method, set up constants like these examples:

MY_MAP = Hash[ActiveRecord::Base.connection.select_all('SELECT thingone, thingtwo from table').map{|one| [one['thingone'], one['thingtwo']]}]
RAW_DATA = `cat the_file`  # However you read and parse your fileCA = State.find_by_name 'California'NY = State.find_by_name 'New York'

These will get executed once in a production app: when the model's class is loaded. Another option: do this initialization in an initializer or other config file. See the config/initializers directory.

Post a Comment for "Ruby On Rails - Storing And Accessing Large Data Sets"