class SurveyBPeriod include Mongoid::Document include Mongoid::Timestamps field :title, :type => String field :start_date, :type => DateTime field :end_date, :type => DateTime validates :start_date, :end_date, :presence => true def self.get_current_survey self.where(:start_date.lte => Time.now, :end_date.gte => Time.now).first end def isAvailable? if start_date <= Time.now and end_date >= Time.now return true else return false end end def get_status_type # status type # reference to config/locales/en.yml and zh-tw.yml # status_types: # type1: 調查中 # type2: 未開始 # type3: 已結束 if start_date <= Time.now and end_date >= Time.now return "type1" end if start_date > Time.now return "type2" end if end_date < Time.now return "type3" end end end