I have a model with a serialized attribute (array). I would like to test the model only if each member of the array is included in predefined parameters.
Example: I have a Person model that has the "mood" attribute. Users can have more than one mood, but each mood should be “happy,” “sad,” “tired,” or “angry.”
The model will look something like this:
class Person < ActiveRecord::Base
MOODS = %w[happy sad tired angry]
attr_accessible :mood
serialize :mood
end
Commented verification does not work. Is there a way to make it work, or do I need a special check?
(Note: I do not want to create a separate mood model.)
source
share