recruitment/app/models/recruit_profile.rb

45 lines
1.0 KiB
Ruby
Raw Normal View History

2017-12-21 19:41:50 +00:00
class RecruitProfile
include Mongoid::Document
include Mongoid::Timestamps
2018-01-01 13:52:15 +00:00
include Slug
2017-12-21 19:41:50 +00:00
EMPLOYEE=1
EMPLOYER=2
field :pseudo_member_id
field :email
2018-01-01 13:52:15 +00:00
field :first_name, as: :slug_title
2017-12-21 19:41:50 +00:00
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