Guest User

Untitled

a guest
Jun 21st, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.04 KB | None | 0 0
  1. class Contact < ActiveRecord::Base
  2. belongs_to :member
  3. belongs_to :completed_form
  4. belongs_to :recent_form
  5. belongs_to :phone_type
  6.  
  7. # VALIDATIONS
  8. def before_validation_on_create
  9. self.phone = phone.gsub(/[^0-9]/, "")
  10. end
  11.  
  12. after_create :map_contact_to_member
  13.  
  14. validates_presence_of :city, :message => "^please enter a City"
  15. validates_length_of :state, :is => 2, :wrong_length => "^please use the 2 character abbreviation for State"
  16. validates_length_of :zip_code, :is => 5, :wrong_length => "^Zip Code should be {{count}} digits"
  17. validates_numericality_of :zip_code, :only_integer => true, :message => "^Zip Code should be composed only of numbers"
  18. validates_length_of :phone, :is => 10, :allow_blank => true, :wrong_length => "^Phone Number needs to be {{count}} digits"
  19. validates_presence_of :phone_type, :if => :phone?, :message => "^if providing a Phone Number please select a Phone Type"
  20.  
  21. #Custom Methods
  22.  
  23. protected
  24. def map_contact_to_member(id)
  25. update_attribute "member_id", '#{id}'
  26. end
  27. end
Add Comment
Please, Sign In to add comment