Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I handle data which must be persisted in a database, but isn't a proper model, in Ruby on Rails?

Imagine a web application written in Ruby on Rails. Part of the state of that application is represented in a piece of data which doesn't fit the description of a model. This state descriptor needs to be persisted in the same database as the models. Where it differs from a model is that there needs to be only one instance of its class and it doesn't have relationships with other classes.

Has anyone come across anything like this?

like image 524
Hans Sjunnesson Avatar asked Sep 22 '08 10:09

Hans Sjunnesson


1 Answers

From your description I think the rails-settings plugin should do what you need.

From the Readme:

"Settings is a plugin that makes managing a table of global key, value pairs easy. Think of it like a global Hash stored in you database, that uses simple ActiveRecord like methods for manipulation. Keep track of any global setting that you dont want to hard code into your rails app. You can store any kind of object. Strings, numbers, arrays, or any object."

http://github.com/Squeegy/rails-settings/tree/master

like image 182
Patrick Ritchie Avatar answered Sep 19 '22 12:09

Patrick Ritchie