Skip to content

Instantly share code, notes, and snippets.

@ColinDKelley
Created June 13, 2012 04:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ColinDKelley/2921928 to your computer and use it in GitHub Desktop.
Save ColinDKelley/2921928 to your computer and use it in GitHub Desktop.
class User < ActiveRecord::Base
attr_default :first_name, 'First'
attr_default :last_name, 'Last'
attr_default :name_addr, lambda { "#{full_name} <#{email}>" }
attr_default :email, lambda { organization.default_email }
def full_name
[first_name, middle_name, last_name].select { |name| !name.blank? } * ' '
end
belongs_to :organization
end
user1 = User.create :email => 'joe@yahoo.com', :name_addr => ‘Joe <joe@yahoo.com>’
user1.name_addr # => "Joe <joe@yahoo.com>"
user2 = User.new
user2.attributes = { :first_name => 'Joe' }
user2.name_addr # => "Joe Last <sales@example.com>"
user3 = User.create :email => 'jane@yahoo.com'
user3.last_name = 'Doe'
user3.name_addr # => "First Doe <jane@yahoo.com>"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment