Articles tagged with: enum

Symbolize attribute values in ActiveRecord

Posted by Andreas on Friday, September 07, 2007 at 12:09 (CEST)
Update: I put together the code below and created a rails plugin from it. It’s called activerecord_symbolize on Github.

ActiveRecord does not natively suppport column types of ENUM or SET. If you want an attribute to act like an ENUM, you’ll most probably use a string and restrict it to certain values using validates_inclusion_of. However, once you’ve got used to Ruby, you’d probably prefer to have symbols as values for these attributes. Here’s a small and easy-to-use snippet that can be used to symbolize values of any ActiveRecord attribute.

Read more »