How do I describe an enumeration column in a Rails 3 migration?
What worked for me was mapping it from symbols to integers
TYPE_MAP = { type_one: 1, type_two:2, another_type:3 }
def type
TYPE_MAP.key(read_attribute(:type))
end
def type=(s)
write_attribute(:type, TYPE_MAP[s])
end
But for the controller you have to map it again like this:
def create
@cupon_type = CuponType.new(params[:cupon_type])
@cupon_type.type = params[:cupon_type][:type].to_sym
Note the .to_sym that overrides the first creation on the object (in my case it was coupons).
Now you can use it like this:
c.type == :type_one
c.type = :type_two