This repository is private.
All pages are served over SSL and all pushing and pulling is done over SSH.
No one may fork, clone, or view it unless they are added as a member.
Every repository with this icon (
) is private.
Every repository with this icon (
This repository is public.
Anyone may fork, clone, or view it.
Every repository with this icon (
) is public.
Every repository with this icon (
| name | age | message | |
|---|---|---|---|
| |
.gitignore | Sun Nov 23 19:28:33 -0800 2008 | |
| |
MIT-LICENSE | Mon May 05 08:02:59 -0700 2008 | |
| |
Manifest | Sun Nov 23 19:28:33 -0800 2008 | |
| |
README.textile | Mon Nov 24 02:32:17 -0800 2008 | |
| |
Rakefile | Sun Nov 23 20:52:24 -0800 2008 | |
| |
init.rb | Sun Nov 23 19:28:33 -0800 2008 | |
| |
lib/ | Sun Nov 23 19:28:33 -0800 2008 | |
| |
magic_enums.gemspec | Sun Nov 23 20:52:24 -0800 2008 | |
| |
test/ | Sun Nov 23 19:28:33 -0800 2008 |
README.textile
or
MagicEnums
Introduction
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.
Install
sudo gem sources -a http://gems.github.com
sudo gem install zachinglis-magic_enums
Usage
In your models
enum_column :status, %w(draft private published)
# This also supplies you with: Post.status_choices
or
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:
Post.status_is_published
or
Person.gender_is_male
Copyright © 2008 Zach Inglis, released under the MIT license







