Guest User

Untitled

a guest
Apr 20th, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.67 KB | None | 0 0
  1. class Contact < ActiveRecord::Base
  2. validates_presence_of :user_id
  3.  
  4. belongs_to :user
  5. has_many :properties, :dependent => :destroy do
  6. # Defined for Contact#properties.
  7. # Use value_for_[abbreviation] to find the value of a property by it's abbreviation.
  8. # ==== Parameters
  9. # *args:: String that matches a Property.abbreviation
  10. # ==== Examples
  11. # contact.properties.value_for_email
  12. # # => would return the value for the property with an abbreviation of email
  13. def method_missing(sym, *args)
  14. return super unless sym.to_s =~ /value_for_(\w*)/
  15. (property = self.find_by_abbreviation($1)) ? property.value : nil
  16. end
  17. end
  18. end
Add Comment
Please, Sign In to add comment