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
- ---------------------------------------------
- class Member < ActiveRecord::Base
- #forms
- #allows user to access all forms completed by the member
- has_many :completed_forms, :as => :data_collection
- accepts_nested_attributes_for :completed_forms
- has_one :recent_form, :as => :data_collection, :class_name => "CompletedForm", :order => "updated_at DESC"
- #aliases
- has_many :aliases
- #contact associations
- #need this information to do traces but can also use the methods on the completed form to see individual
- has_many :contacts
- has_many :contacts, :through => :completed_forms
- accepts_nested_attributes_for :contacts
- #need to decide if this information really needs to be accessed from members or only relative to the actual forms they complete
- has_many :messenger_usages, :through => :completed_forms
- has_many :online_usages, :through => :completed_forms
- has_many :permitted_contacts, :through => :completed_forms
- #demographic associations
- #allows user to access demographic information based on the set of forms it originates from
- has_many :demographics
- has_many :ethnic_races, :through => :demographics
- has_many :sexes, :through => :demographics
- has_many :serostatuses, :through => :demographics
- has_many :genders, :through => :demographics
- has_many :gender_expressions, :through => :demographics
- has_many :sexual_orientations, :through => :demographics
- # VALIDATIONS
- validates_presence_of :first_name, :message => "^Please enter member's First Name"
- validates_presence_of :last_name, :message => "^Please enter member's Last Name"
- def age
- age = Date.today.year - self.dob.year
- if Date.today.month < self.dob.month || (Date.today.month == self.dob.month && self.dob.day >= Date.today.day)
- age = age - 1
- end
- return age
- end
- def fullName
- fullName = "#{self.first_name}" " " "#{self.middle_name}" " " "#{self.last_name}"
- end
- end
- ---------------------------------------------
- class CompletedForm < ActiveRecord::Base
- belongs_to :data_collection, :polymorphic => true
- belongs_to :form_version
- has_one :contact
- has_many :messenger_usages
- has_many :online_usages
- has_many :permitted_contacts
- has_one :demographic
- accepts_nested_attributes_for :contact
- accepts_nested_attributes_for :demographic
- end
Add Comment
Please, Sign In to add comment