Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # == Schema Information
- # Schema version: 20090506151430
- #
- # Table name: contacts
- #
- # id :integer not null, primary key
- # profile_id :integer not null
- # address_id :integer not null
- # created_at :datetime
- # updated_at :datetime
- # client_id :integer not null
- # location :string(100)
- #
- class Contact < ActiveRecord::Base
- belongs_to :client
- belongs_to :address
- belongs_to :profile
- accepts_nested_attributes_for :profile, :address
- validates_presence_of :client_id, :profile, :address
- validates_length_of :location, :maximum => 100, :allow_blank => true
- validate :validate_fax, :validate_work
- private
- def validate_fax
- if !profile.nil? && profile.fax.blank?
- errors.add(:profile_fax, "can't be blank")
- profile.errors.add(:fax, "can't be blank")
- end
- end
- def validate_work
- if !profile.nil? && profile.work.blank?
- errors.add(:profile_work, "can't be blank")
- profile.errors.add(:work, "can't be blank")
- end
- end
- end
Add Comment
Please, Sign In to add comment