Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Contact < ActiveRecord::Base
- belongs_to :member
- belongs_to :completed_form
- belongs_to :recent_form
- belongs_to :phone_type
- # VALIDATIONS
- def before_validation_on_create
- self.phone = phone.gsub(/[^0-9]/, "")
- end
- after_create :map_contact_to_member
- validates_presence_of :city, :message => "^please enter a City"
- validates_length_of :state, :is => 2, :wrong_length => "^please use the 2 character abbreviation for State"
- validates_length_of :zip_code, :is => 5, :wrong_length => "^Zip Code should be {{count}} digits"
- validates_numericality_of :zip_code, :only_integer => true, :message => "^Zip Code should be composed only of numbers"
- validates_length_of :phone, :is => 10, :allow_blank => true, :wrong_length => "^Phone Number needs to be {{count}} digits"
- validates_presence_of :phone_type, :if => :phone?, :message => "^if providing a Phone Number please select a Phone Type"
- #Custom Methods
- protected
- def map_contact_to_member(id)
- update_attribute "member_id", '#{id}'
- end
- end
Add Comment
Please, Sign In to add comment