socialforge/app/models/course.rb

51 lines
1.5 KiB
Ruby
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

class Course < ActiveRecord::Base
include Redmine::SafeAttributes
attr_accessible :code, :extra, :name, :state, :tea_id, :time , :location, :state, :term, :password
belongs_to :project, :class_name => 'Project', :foreign_key => :extra, primary_key: :identifier
belongs_to :teacher, :class_name => 'User', :foreign_key => :tea_id # 定义一个方法teacher该方法通过tea_id来调用User表
belongs_to :school, :class_name => 'School', :foreign_key => :school_id #定义一个方法school该方法通过school_id来调用School表
has_many :bid
validates_presence_of :password, :term
validates_format_of :class_period, :message => "class period can only digital!", :with =>/^[1-9]\d*$/
safe_attributes 'extra',
'time',
'name',
'extra',
'code',
'location',
'tea_id',
'password',
'term',
'password'
#自定义验证
def validate
if !class_period.match([0-9])
errors.add_to_base("class period can only digital")
end
end
def get_endup_time
begin
end_time = Time.parse(self.endup_time)
rescue Exception => e
end_time = Time.parse("3000-01-01")
Rails.logger.error "[Error] course endup_time error. ===> #{e}"
ensure
return end_time
end
end
def get_time
begin
time = Date.new(self.time).to_time
rescue Exception => e
time = Time.parse("3000-01-01")
Rails.logger.error "[Error] course time error. ===> #{e}"
ensure
return time
end
end
end