Sha256: e03b51f295f814a8f571ff6f046f90b28120432e6521183831fbbc029823d87a

Contents?: true

Size: 1008 Bytes

Versions: 4

Compression:

Stored size: 1008 Bytes

Contents

= A rails plugin for active_record model
 manage mapping column 

= Usage
 In your model,for example in Post,you have a column named status(integer), 1 means normal, 2 means draft, 3 means deleted.
Now,with enum_attr plugin,you just decalre:

    enum_attr :status, [ ["正常", 1, "normal"], ["草稿", 2, "draft"], ["已删除", 3, "deleted"] ]

with this declare, you have these code below:

consts: 
        STATUS_NORMAL = 1; STATUS_DRAFT = 2; STATUS_DELETED = 3
        ENUMS_STATUS = [ ["正常", 1], ["草稿", 2], ["已删除", 3] ] # this is for select tag

valitates:
        validates_inclusion_of "status", :in => [1,2,3], :allow_nil => true

methods:
     # instant_method
     def status_name
       # ... return readable status name according to stauts value(integer)
     end


= See more detail in spec test
更多用法见spec/enum_spec.rb文件

= Inspiration
  Thanks Quakewang
  http://quake.javaeye.com/blog/448235 

= Copyright

Copyright © 2010 Qichunren. See LICENSE for details. 

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
enum_attr-1.0.2 README.rdoc
enum_attr-1.0.1 README.rdoc
enum_attr-1.0.0 README.rdoc
enum_attr-0.0.7 README.rdoc