Created
June 13, 2012 04:54
-
-
Save ColinDKelley/2921928 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 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 => '[email protected]', :name_addr => ‘Joe <[email protected]>’ | |
user1.name_addr # => "Joe <[email protected]>" | |
user2 = User.new | |
user2.attributes = { :first_name => 'Joe' } | |
user2.name_addr # => "Joe Last <[email protected]>" | |
user3 = User.create :email => '[email protected]' | |
user3.last_name = 'Doe' | |
user3.name_addr # => "First Doe <[email protected]>" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment