class RecruitProfile include Mongoid::Document include Mongoid::Timestamps include Slug EMPLOYEE=1 EMPLOYER=2 field :pseudo_member_id field :email field :first_name, as: :slug_title field :last_name field :user_type, type: Integer, default: 1 scope :employers, ->{ where(user_type: self::EMPLOYER) } scope :employees, ->{ where(user_type: self::EMPLOYEE) } has_one :employee_profile, :autosave => true, :dependent => :destroy accepts_nested_attributes_for :employee_profile, :allow_destroy => true has_one :employer_profile, :autosave => true, :dependent => :destroy accepts_nested_attributes_for :employer_profile, :allow_destroy => true def name self.first_name + " " + self.last_name rescue self.email end def profile if self.is_employer? self.employer_profile elsif self.is_employee? self.employee_profile end end def is_employer? self.user_type == RecruitProfile::EMPLOYER end def is_employee? self.user_type == RecruitProfile::EMPLOYEE end end