Forum: Ruby on Rails Fixed set of values for an attribute and migrations

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
0fc60326968a0eaccf30330fe6758375?d=identicon&s=25 Juan Kinunt (kinunt)
on 2009-02-03 15:10
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.
D69d23d8e811e8ab2a8593380d6ede63?d=identicon&s=25 Jeff Emminger (jemminger)
on 2009-02-03 21:21
(Received via mailing list)
Check out validates_inclusion_of

http://api.rubyonrails.org/classes/ActiveRecord/Va...



On Feb 3, 9:10 am, Juan Kinunt <rails-mailing-l...@andreas-s.net>
This topic is locked and can not be replied to.