how (replace|create) an enum field on rails 2.0 migrations?

后端 未结 10 1634
轮回少年
轮回少年 2020-12-07 10:27

I would like to create an enum field at sone migration I\'m doing, I tried searching in google but I can\'t find the way to do it in the migration

the only thing I f

10条回答
  •  南方客
    南方客 (楼主)
    2020-12-07 10:49

    Look at tip #3 on http://zargony.com/2008/04/28/five-tips-for-developing-rails-applications

    This exactly what you need!

     class User < ActiveRecord::Base
       validates_inclusion_of :status, :in => [:active, :inactive]
    
       def status
         read_attribute(:status).to_sym
       end
    
       def status= (value)
         write_attribute(:status, value.to_s)
       end
     end
    

    HTH

提交回复
热议问题