Permalink
Browse files

Pulled common relationships out into Contact module

  • Loading branch information...
1 parent e81121f commit a35b9123a6f698990c94affa3c6dd164db120e8a @jcasimir jcasimir committed Apr 22, 2011
Showing with 16 additions and 10 deletions.
  1. +2 −5 app/models/company.rb
  2. +8 −0 app/models/contact.rb
  3. +6 −5 app/models/person.rb
View
@@ -1,8 +1,5 @@
class Company < ActiveRecord::Base
attr_accessible :name
-
- validates_presence_of :name
-
- has_many :phone_numbers, :as => :contact
- has_many :email_addresses, :as => :contact
+ validates_presence_of :name
+ include Contact
end
View
@@ -0,0 +1,8 @@
+module Contact
+ extend ActiveSupport::Concern
+
+ included do
+ has_many :phone_numbers, :as => :contact
+ has_many :email_addresses, :as => :contact
+ end
+end
View
@@ -1,8 +1,9 @@
class Person < ActiveRecord::Base
- attr_accessible :first_name, :last_name
+ attr_accessible :first_name, :last_name
+ validates_presence_of :first_name, :last_name
+ include Contact
- validates_presence_of :first_name, :last_name
-
- has_many :phone_numbers, :as => :contact
- has_many :email_addresses, :as => :contact
+ def to_s
+ "#{last_name}, #{first_name}"
+ end
end

0 comments on commit a35b912

Please sign in to comment.