Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Clever enums in rails using module style
class Photo < ActiveRecord::Base
module Statues
QUEUED = 'queued'
NEW = 'new'
def self.values
constants.map(&method(:const_get))
end
# you can define more special methods as you wanted for Statues
end
validates :status, inclusion: {in: Statues.values }
def change_status
self.status = Statues::NEW
end
end
@rainchen
Copy link
Author

rainchen commented Jun 5, 2013

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment