diff --git a/app/controllers/student_work_controller.rb b/app/controllers/student_work_controller.rb index 9ce0f76f7..5e13149df 100644 --- a/app/controllers/student_work_controller.rb +++ b/app/controllers/student_work_controller.rb @@ -734,24 +734,33 @@ class StudentWorkController < ApplicationController end def destroy - if @work.destroy - if @homework.homework_type == 3 && @homework.homework_detail_group.base_on_project == 1 - pros = @work.student_work_projects.where("is_leader = 0") - pros.each do |pro| - pro.destroy - end - project = @work.student_work_projects.where("is_leader = 1").first - project.update_attributes(:student_work_id => nil) - elsif @homework.homework_type == 3 && @homework.homework_detail_group.base_on_project == 0 - @work.student_work_projects.each do |pro2| - pro2.destroy + if @homework.homework_type == 3 + if @work.destroy + if @homework.homework_detail_group.base_on_project == 1 + pros = @work.student_work_projects.where("is_leader = 0") + pros.each do |pro| + pro.destroy + end + project = @work.student_work_projects.where("is_leader = 1").first + project.update_attributes(:student_work_id => nil) + elsif @homework.homework_detail_group.base_on_project == 0 + @work.student_work_projects.each do |pro2| + pro2.destroy + end end end - respond_to do |format| - format.html { - redirect_to student_work_index_url(:homework => @homework.id) - } - end + else + @work.attachments.destroy_all + @work.student_works_scores.destroy_all + @work.course_messages.destroy_all + @work.student_work_tests.destroy_all + @work.update_attributes(:work_status => 0, :name => "#{@homework.name}的作品提交", :description => nil, :late_penalty => 0, :commit_time => nil,:final_score => nil,:teacher_score => nil,:student_score => nil,:teaching_asistant_score => nil,:system_score => 0,:work_score => nil) + @work.update_column("work_score",nil) + end + respond_to do |format| + format.html { + redirect_to student_work_index_url(:homework => @homework.id) + } end end @@ -794,6 +803,7 @@ class StudentWorkController < ApplicationController elsif @homework.homework_type == 1 @work.update_attributes(:work_status => 0, :name => "#{@homework.name}的作品提交", :description => nil, :late_penalty => 0, :commit_time => nil) @work.attachments.destroy_all + @work.course_messages.destroy_all end @student_work = StudentWork.new respond_to do |format| diff --git a/app/models/student_work.rb b/app/models/student_work.rb index 09ef15583..183570081 100644 --- a/app/models/student_work.rb +++ b/app/models/student_work.rb @@ -1,6 +1,6 @@ #学生提交作品表 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, :simi_id, :simi_value, :work_status, :commit_time + attr_accessible :name, :description, :homework_common_id, :user_id, :final_score, :teacher_score, :student_score, :teaching_asistant_score, :system_score, :work_score, :project_id, :is_test, :simi_id, :simi_value, :work_status, :commit_time belongs_to :homework_common belongs_to :user