daily pastebin goal
28%
SHARE
TWEET

Untitled

a guest Mar 13th, 2018 62 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ## preferred_contact.rb
  2.  
  3. module ContactMethods
  4.   def self.included(base)
  5.     base.class_eval do
  6.      
  7.       has_many :email_addresses,
  8.         :extend => ContactFinders,
  9.         :dependent => :destroy
  10.      
  11.       has_many :phone_numbers,
  12.         :conditions => {:is_fax => false},
  13.         :extend => ContactFinders
  14.      
  15.       has_many :fax_numbers,
  16.         :conditions => {:is_fax => true},
  17.         :class_name => 'PhoneNumber',
  18.         :extend => ContactFinders
  19.      
  20.       has_many :mailing_addresses,
  21.         :as => :addressable,
  22.         :extend => ContactFinders
  23.      
  24.      
  25.       has_many :im_accounts,
  26.         :as => :imable,
  27.         :extend => ContactFinders
  28.        
  29.     end
  30.   end
  31. end
  32.  
  33. ## contact_finders.rb
  34. module ContactFinders
  35.   def preferred
  36.     find(:first, :conditions => {:preferred => true})
  37.   end
  38. end
  39.  
  40. ## user.rb
  41. class User < ActiveRecord::Base
  42. has_many :email_addresses,
  43.         :extend => ContactFinders,
  44.         :dependent => :destroy
  45. end
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top