#encoding: utf-8 class GraduationTopic < ActiveRecord::Base include Redmine::SafeAttributes belongs_to :user belongs_to :course attr_accessible :user_id, :course_id, :city, :description, :name, :property, :property_two, :province, :repeat, :source, :source_unit, :status, :tea_id, :topic_type, :is_public safe_attributes 'city', 'description', 'name', 'property', 'property_two', 'province', 'repeat', 'source', 'source_unit', 'status', 'topic_type' # status 0:待选中 1:待确认 2:已确认 belongs_to :teacher, :class_name => 'User', :foreign_key => :tea_id # 定义一个方法teacher,该方法通过tea_id来调用User表 has_many :journals_for_messages, :as => :jour, :dependent => :destroy has_many :praise_tread, as: :praise_tread_object, dependent: :destroy has_one :praise_tread_cache, as: :object, dependent: :destroy has_many :student_graduation_topics, :dependent => :destroy has_many :course_acts, :class_name => 'CourseActivity',:as =>:course_act ,:dependent => :destroy after_create :act_as_course_activity acts_as_attachable def topic_type_name name = "" case topic_type when 1 name = "设计" when 2 name = "论文" when 3 name = "创作" end name end def source_name name = "" case source when 1 name = "生产/社会实际" when 2 name = "结合科研" when 3 name = "其它" end name end def property_name name = "" case property when 1 name = "真题" when 2 name = "模拟题" end name end def property_two_name name = "" case property_two when 1 name = "纵向课题" when 2 name = "横向课题" when 3 name = "自选" end name end def repeat_name name = "" case repeat when 1 name = "新题" when 2 name = "往届题,有新要求" when 3 name = "往届题,无新要求" end name end #课程动态公共表记录 def act_as_course_activity if self.course if self.course_acts.size == 0 self.course_acts << CourseActivity.new(:user_id => self.user_id,:course_id => self.course_id) end end end end