Skip to content

Instantly share code, notes, and snippets.

@laspluviosillas
Created March 24, 2013 15:01
Show Gist options
  • Save laspluviosillas/5232261 to your computer and use it in GitHub Desktop.
Save laspluviosillas/5232261 to your computer and use it in GitHub Desktop.
class Adoption < ActiveRecord::Base
has_one :adopter_info, :as => :contact, :class_name => "ContactInfo"
accepts_nested_attributes_for :adopter_info
end
class ContactInfo < ActiveRecord::Base
attr_accessible :address, :email, :full_name, :phone, :state, :city, :zip
belongs_to :contact, polymorphic: true
validate :must_have_form_of_contact
private
# Either phone, email, or address, but not all are required.
def must_have_form_of_contact
if phone.blank? && email.blank? && (address.blank? || city.blank? || state.blank? || zip.blank?)
errors[:base] << "You must enter a phone, address, or email"
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment