Rails persistent storage keystore: in database only?

I've developed a Rails application with a lot of models organized in dedicated tables (as it should be).

Lately I've been trying to extract hard-coded options for my app (titles, etc) into YAML config files. While I am quite happy with this approach, the problem is that I cannot modify them on the fly through an application, only from a text editor.

I have now looked at using a dedicated database table to store them, but that seems like an overkill since this one settings_table

will contain so many fields and only one object.

Basically what I'm looking for is a simple long lasting (like forever) keystore. The Reddis server will obviously be redundant. It looks like ActiveRecord :: Cache :: Store might be the solution, although I'm not sure about the long term part.

What is the "true" Rails way to achieve this?

Edit: data types

Several dozen key-> string values, for example:

page_title: "My Awesome Website"
full_name: "James Bond"
occupation: "Secret Agent"
facebook_account: "www.facebook.com/007"



source to share

1 answer

Instead of having one column for each key, you can simply have one column and store the data in a sequential format. That being said, although in the future if you want to add more data, there will be no problem.

http://apidock.com/rails/ActiveRecord/AttributeMethods/Serialization/ClassMethods/serialize will give you some links, otherwise you can also use the to_json and JSON.parse methods, treating the data as a hash.

In your case, as shown below config_data = {page_title: "My Great Site", full_name: "James Bond", Occupation: "Secret Agent", facebook_account: "www.facebook.com/007"}

config_data.to_json can be stored in the database directly and readable by JSON.parse (dbvalue)



All Articles