Skip to content

Provides rudimentary support for model enums in Rails 3.

Notifications You must be signed in to change notification settings

shakerlxxv/rails3-enum-support

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 

Repository files navigation

Rails 3 / Enum Support

Provides rudimentary enum support for Rails 3 model classes.

Getting Started

  1. Require the enum_support gem in each model class you wish to use it in:

    require 'enum_support'
    
  2. Then, make sure to extend the module:

    Class IceCream < ActiveRecord::Base
      extend EnumSupport
    
  3. Finally, specify as many enum attributes as you want within the class:

    enum :flavour, %w{vanilla chocolate strawberry neopolitan}
    

At this point, you can use your enumeration just as you would with any other attribute you specify:

yum = IceCream.new
yum.flavour = :chocolate
yum.flavour # returns :chocolate

Validation is also performed when attempting to save a model instance. Setting an enum attribute to a value not in the initial set will render the instance invalid.

About

Provides rudimentary support for model enums in Rails 3.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published