Question: I want to save **settings for my users** and some of them would be one out of a **predefined list**! Using <https://github.com/ledermann/rails-settings> ATM.

The setting for f.e. weight\_unit would be out of [:kg, :lb].

I don't really want to hardcode that stuff into controller or view code. 

It's kind of a common functionality, so I was wondering: Did anyone come up with some way of abstracting that business into **class constants** or the **database** in a DRY fashion?

Answer: 
Usually, when I have to store some not important information which I don't care to query individually, I store them on a serialized column.

In your case you could create a new column in your users table (for example call it "settings").

After that you add to user model

```
serialize :settings, Hash

```

from this moment you can put whatever you like into settings, for example

```
user.settings = {:weight_unit => :kg, :other_setting1 => 'foo', :other_setting2 => 'bar'}

```

and saving with user.save you will get, in settings column, the serialized data.

Rails does also de-serialize it so after fetching a user's record, calling user.settings, you will get all saved settings for the user.

To get more information on serialize() refer to docs: <http://api.rubyonrails.org/classes/ActiveRecord/AttributeMethods/Serialization/ClassMethods.html#method-i-serialize>

**UPDATE1**
To ensure that settings are in the predefined list you can use validations on your user model.

**UPDATE2**
Usually, if there are some pre-defined values it's a good habit to store them in a constant inside the related model, in this way you have access to them from model (inside and outside). Acceptable values does not change by instance so it makes sense to share them between all. An example which is more valuable than any word. Defining in your User model:

```
ALLOWED_SETTINGS = {:weight_unit => [:kg, :lb],
                  :eyes_color => [:green, :blue, :brows, :black],
                  :hair_length => [:short, :long]}

```

you can use it BOTH

* outside the model itself, doing

User::ALLOWED\_SETTINGS
* inside your model (in validations, instance methods or wherever you want) using:

ALLOWED\_SETTINGS
If you are using PostgreSQL, I think you can watch to HStore with Rails 4 + this gem <https://github.com/devmynd/hstore_accessor>