class AsiaProject include Mongoid::Document include Mongoid::Timestamps include Slug field :project_name, :type => String, :default => "", :localize => true, :as => :slug_title field :start_date, :type => Date field :end_date, :type => Date field :sponsor, :type => String, :default => "", :localize => true field :sort_position, type: Integer, default: 0 field :rss2_id belongs_to :asia_teacher, index: true scope :sort_order, ->{order({start_date: -1})} index({start_date: -1}, { unique: false, background: true }) def date if self.start_date.nil? && self.end_date.nil? "" else "#{self.start_date} ~ #{self.end_date}" end end end