forked from saurabh/orbit4-5
42 lines
998 B
Ruby
42 lines
998 B
Ruby
class MemberProfile
|
|
include Mongoid::Document
|
|
include Mongoid::Timestamps
|
|
|
|
field :first_name, type: String, localize: true
|
|
field :last_name, type: String, localize: true
|
|
field :sex
|
|
field :sid
|
|
field :office_tel
|
|
field :birthday, type: DateTime
|
|
field :address
|
|
field :personal_website
|
|
field :autobiography, type: String, localize: true
|
|
field :email, type: String
|
|
|
|
VALID_EMAIL_FORMAT = /\A[^@\s]+@([^@.\s]+\.)+[^@.\s]+\z/
|
|
validates :email, uniqueness: true, format: { with: VALID_EMAIL_FORMAT }
|
|
|
|
has_one :user
|
|
has_and_belongs_to_many :roles
|
|
has_and_belongs_to_many :role_statuses
|
|
|
|
mount_uploader :avatar, AvatarUploader
|
|
paginates_per 10
|
|
|
|
def name
|
|
if self.first_name || self.last_name
|
|
"#{self.first_name} #{self.last_name}"
|
|
end
|
|
end
|
|
|
|
def disable_role=(var)
|
|
var[:id].each do |id,val|
|
|
if (val=="true")
|
|
self.role_ids.reject!{|t| t.to_s == id}
|
|
elsif(val=="false")
|
|
self.role_ids += Array(id)
|
|
end
|
|
end
|
|
end
|
|
end
|