Valid options from hash

Which is the best way to create a thin key/value related to some
model? where a field only could insert those values (keys as 0,1) and
where could be showed the values (as Red, Blue) from a drop-list

COLOUR_OPTIONS = {0=>"Red", 1=>"Blue"}

t.string :colour

validates_inclusion_of :colour, :in => COLOUR_OPTIONS.keys

That might give you some ideas for starters.

I will say that I would prefer to just store the actual values (“Red”, “Blue”, etc.) or if you want to store numeric keys, then create an actual table and setup an association.

class Whatever < ActiveRecord::Base
belongs_to :colour

class Colour < ActiveRecord::Base
has_many :whatevers

Michael Guterl

Thanks. I'll use tables.