Sha256: 41e8fd9e24cb00363e1107a28aec53a4a41879c709fa5a61dccb9b77ce7b1350
Contents?: true
Size: 1.35 KB
Versions: 1
Compression:
Stored size: 1.35 KB
Contents
== ActsAsEnum 主要应用于有枚举类型属性的Model,这个插件会帮我们生成一些常用到的方法。 如:枚举数组常量,每个元素的常量和布尔方法,属性的名字,Named scope方法 Support rails 3 == Usage class User < ActiveRecord::Base acts_as_enum :status, :enum => [ ['disable', 0, '冻结'], ['enable', 1, '激活'] ] end Also can usage alias enum_attr enum_attr :status, :enum => [ ['disable', 0, '冻结'], ['enable', 1, '激活'] ] Will generate bellow: Constants: User::STATUSES, User::DISABLE, User::ENABLE Named scopes: User.enable, User.disable Class methods: User.status_options Instance methods: user.status_name, user.enable?, user.disable? If with option prefix is true: acts_as_enum :status, :enum => [ ['disable', 0, '冻结'], ['enable', 1, '激活'] ], :prefix => true Will generate bellow: User::STATUS_DISABLE, User::STATUS_ENABLE, User.status_enable, User.status_disable, user.status_enable?, user.status_disable? == Install git clone git://github.com/wenke/acts_as_enum.git OR rails 2 ./script/plugin install git://github.com/wenke/acts_as_enum.git rails 3 rails plugin install git://github.com/wenke/acts_as_enum.git == Note Copyright (c) 2010 liangwenke8@gmail.com, released under the MIT license
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
acts_as_enum-0.1.0 | README.rdoc |