#学生提交作品表 class StudentWork < ActiveRecord::Base attr_accessible :name, :description, :homework_common_id, :user_id, :final_score, :teacher_score, :student_score, :teaching_asistant_score, :project_id, :is_test belongs_to :homework_common belongs_to :user has_many :student_works_evaluation_distributions, :dependent => :destroy has_many :student_works_scores, :dependent => :destroy belongs_to :project has_many :student_work_tests, order: 'id desc' before_destroy :delete_praise before_save :set_program_score, :set_src acts_as_attachable def delete_praise PraiseTread.where("praise_tread_object_id = #{self.id} AND praise_tread_object_type = 'StudentWork'").destroy_all end def last_test student_work_tests.order('id desc').first end private def set_program_score if homework_common.is_program_homework? #编程作业,学生提交作品后计算系统得分 #根据最后一次测试计算得分 unless last_test self.system_score = 0 else self.system_score = last_test.test_score end end end def set_src self.description = last_test.src if last_test end end