Skip to content

Instantly share code, notes, and snippets.

@obrie
Created September 7, 2008 14:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save obrie/9262 to your computer and use it in GitHub Desktop.
Save obrie/9262 to your computer and use it in GitHub Desktop.
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