Created
September 7, 2008 14:13
-
-
Save obrie/9262 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 CreditCardType < ActiveRecord::Base | |
acts_as_enumeration | |
column :display_name | |
# defaults :name => :default_name # Uses the active_record_defaults plugin | |
def initialize(attributes = nil) | |
super | |
self.name = default_name unless attributes && attributes.include?(:name) | |
end | |
private | |
def default_name | |
display_name.gsub(/[^A-Za-z0-9-]/, '').underscore | |
end | |
create :id => 1, :display_name => 'Visa' | |
create :id => 2, :display_name => 'Mastercard' | |
create :id => 3, :display_name => 'American Express', :name => 'amex' | |
create :id => 4, :display_name => 'Discover' | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment