experiment/app/models/subject.rb

46 lines
1.2 KiB
Ruby

class Subject
include Mongoid::Document
include Mongoid::Timestamps
include OrbitModel::Status
include OrbitTag::Taggable
include OrbitCategory::Categorizable
include Slug
field :title,as: :slug_title, localize: true
field :image_description, localize: true
field :venue, localize: true
field :tel, localize: true
field :professor1, localize: true
field :professor2, localize: true
field :facility, localize: true
field :direction , localize: true
field :student, localize: true
field :email_member_ids
field :co_professor_ids
field :rss2_id
mount_uploader :image, ImageUploader
has_many :subject_links, :autosave => true, :dependent => :destroy
accepts_nested_attributes_for :subject_links, :allow_destroy => true
scope :can_display, ->{where(:is_hidden=>false,:title.ne => "").order_by([:is_top, :desc])}
before_save :clean_values
def co_professors
MemberProfile.find(self.co_professor_ids) rescue []
end
def email_members
MemberProfile.find(self.email_member_ids) rescue []
end
protected
def clean_values
self.subject_links.each do |link|
link.delete if link.url.blank? && link.title.blank?
end
self.tags.delete('')
end
end