Guest User

Untitled

a guest
Jun 17th, 2018
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.07 KB | None | 0 0
  1. # == Schema Information
  2. # Schema version: 20090506151430
  3. #
  4. # Table name: contacts
  5. #
  6. # id :integer not null, primary key
  7. # profile_id :integer not null
  8. # address_id :integer not null
  9. # created_at :datetime
  10. # updated_at :datetime
  11. # client_id :integer not null
  12. # location :string(100)
  13. #
  14.  
  15. class Contact < ActiveRecord::Base
  16. belongs_to :client
  17. belongs_to :address
  18. belongs_to :profile
  19. accepts_nested_attributes_for :profile, :address
  20.  
  21. validates_presence_of :client_id, :profile, :address
  22. validates_length_of :location, :maximum => 100, :allow_blank => true
  23.  
  24. validate :validate_fax, :validate_work
  25.  
  26. private
  27. def validate_fax
  28. if !profile.nil? && profile.fax.blank?
  29. errors.add(:profile_fax, "can't be blank")
  30. profile.errors.add(:fax, "can't be blank")
  31. end
  32. end
  33.  
  34. def validate_work
  35. if !profile.nil? && profile.work.blank?
  36. errors.add(:profile_work, "can't be blank")
  37. profile.errors.add(:work, "can't be blank")
  38. end
  39. end
  40. end
Add Comment
Please, Sign In to add comment