Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Contact < ActiveRecord::Base
- validates_presence_of :user_id
- belongs_to :user
- has_many :properties, :dependent => :destroy do
- # Defined for Contact#properties.
- # Use value_for_[abbreviation] to find the value of a property by it's abbreviation.
- # ==== Parameters
- # *args:: String that matches a Property.abbreviation
- # ==== Examples
- # contact.properties.value_for_email
- # # => would return the value for the property with an abbreviation of email
- def method_missing(sym, *args)
- return super unless sym.to_s =~ /value_for_(\w*)/
- (property = self.find_by_abbreviation($1)) ? property.value : nil
- end
- end
- end
Add Comment
Please, Sign In to add comment