# Fixed set of values for an attribute and migrations

**URL:** <https://www.ruby-forum.com/t/fixed-set-of-values-for-an-attribute-and-migrations/159331>\
**Category:** Rails\
**Created:** [February 3, 2009, 3:10pm UTC](https://www.ruby-forum.com/t/fixed-set-of-values-for-an-attribute-and-migrations/159331 "2009-02-03T15:10:21Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![kinunt](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/7c8e57/32.png) [@kinunt](https://www.ruby-forum.com/u/kinunt)\
**Post date:** [February 3, 2009, 3:10pm UTC](https://www.ruby-forum.com/t/fixed-set-of-values-for-an-attribute-and-migrations/159331/1 "2009-02-03T15:10:21Z")

</div>

Hi,  
I have a model with three attributes that could be a fixed set of  
different values. Each attribute does not have sufficient entity to be a  
class (in my opinion) and I prefer to not to create classes in order to  
store them.  
For example, one attribute can be only three strings: phone, email or  
fax.  
The second, two strings: building or garage.  
The correct way of doing this is restricting to this values in the  
model?  
Is there something I can/have to do in the migration?  
I’m thinking about a validation of each field in the model and a  
selection-option field in the forms. Is this the best pattern in order  
to implement this? Would you prefer to create models for each of this  
attributes?  
Hope I explained myself properly.  
Thanks.

---

<div class="post-metadata">

**Author:** ![kinunt](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/7c8e57/32.png) [@kinunt](https://www.ruby-forum.com/u/kinunt)\
**Post date:** [February 3, 2009, 9:21pm UTC](https://www.ruby-forum.com/t/fixed-set-of-values-for-an-attribute-and-migrations/159331/2 "2009-02-03T21:21:59Z")

</div>

Check out validates\_inclusion\_of

[http://api.rubyonrails.org/classes/ActiveRecord/Validations/ClassMethods.html#M002112](http://api.rubyonrails.org/classes/ActiveRecord/Validations/ClassMethods.html#M002112)

On Feb 3, 9:10 am, Juan K. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
