RAILS 2.1+ only!
A nice way to have enums in Rails.
Enumerations are easy as integers, however I want to take a text approach to it as soon as rearranging integers can get fussy.
sudo gem sources -a http://gems.github.com
sudo gem install zachinglis-magic_enums
In your models
enum_column :status, %w(draft private published) # This also supplies you with: Post.status_choices
enum_column :gender, ['male', 'female']
This also supplies you with: Person.gender_choices
It also supplies you with the handy method:
In your controller
In your controller, you can check the status
post_record.status_is_published? or simply by calling
person_record.gender to find it out in words, as you would normally.
You can also do find calls (Using named_scope) like so:
Copyright © 2008 Zach Inglis, released under the MIT license