Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Pulled common relationships out into Contact module

  • Loading branch information...
commit a35b9123a6f698990c94affa3c6dd164db120e8a 1 parent e81121f
Jeff Casimir authored
7  app/models/company.rb
... ...
@@ -1,8 +1,5 @@
1 1
 class Company < ActiveRecord::Base
2 2
   attr_accessible :name
3  
-  
4  
-  validates_presence_of :name
5  
-  
6  
-  has_many :phone_numbers, :as => :contact
7  
-  has_many :email_addresses, :as => :contact
  3
+  validates_presence_of :name  
  4
+  include Contact
8 5
 end
8  app/models/contact.rb
... ...
@@ -0,0 +1,8 @@
  1
+module Contact
  2
+  extend ActiveSupport::Concern
  3
+  
  4
+  included do
  5
+    has_many :phone_numbers, :as => :contact  
  6
+    has_many :email_addresses, :as => :contact
  7
+  end
  8
+end
11  app/models/person.rb
... ...
@@ -1,8 +1,9 @@
1 1
 class Person < ActiveRecord::Base
2  
-  attr_accessible :first_name, :last_name
  2
+  attr_accessible :first_name, :last_name  
  3
+  validates_presence_of :first_name, :last_name  
  4
+  include Contact
3 5
   
4  
-  validates_presence_of :first_name, :last_name
5  
-  
6  
-  has_many :phone_numbers, :as => :contact  
7  
-  has_many :email_addresses, :as => :contact
  6
+  def to_s
  7
+    "#{last_name}, #{first_name}"
  8
+  end
8 9
 end

0 notes on commit a35b912

Please sign in to comment.
Something went wrong with that request. Please try again.