recruitment/app/models/recruit_profile.rb

44 lines
1012 B
Ruby
Raw Normal View History

2017-12-21 19:41:50 +00:00
class RecruitProfile
include Mongoid::Document
include Mongoid::Timestamps
EMPLOYEE=1
EMPLOYER=2
field :pseudo_member_id
field :email
field :first_name
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