Created
January 9, 2012 02:45
-
-
Save akinsgre/1580740 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ContactMethod < ActiveRecord::Base | |
validates_presence_of :name | |
def self.select_options | |
descendants.map { |c| c.to_s }.sort | |
end | |
end | |
class Phone < ContactMethod | |
end | |
class TextMsg < ContactMethod | |
end | |
[gakins@Somnambulist contact]$ rails c | |
Loading development environment (Rails 3.1.3) | |
ruby-1.9.2-p290 :001 > ContactMethod.select_options | |
=> [] | |
ruby-1.9.2-p290 :002 > Phone.new | |
=> #<Phone id: nil, name: nil, type: 0, created_at: nil, updated_at: nil> | |
ruby-1.9.2-p290 :003 > TextMsg.new | |
=> #<TextMsg id: nil, name: nil, type: 0, created_at: nil, updated_at: nil> | |
ruby-1.9.2-p290 :004 > ContactMethod.select_options | |
=> ["Phone", "TextMsg"] | |
ruby-1.9.2-p290 :005 > |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment