From f5cfd7258d32493b93143c3e628875e5a40f0ec7 Mon Sep 17 00:00:00 2001 From: sw <939547590@qq.com> Date: Sat, 1 Aug 2015 14:27:32 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E7=BC=96=E7=A8=8B=E4=BD=9C?= =?UTF-8?q?=E4=B8=9A=E6=97=B6=EF=BC=8C=E5=AF=B9=E5=B7=B2=E9=80=9A=E8=BF=87?= =?UTF-8?q?=E6=B5=8B=E8=AF=95=E3=80=81=E6=9C=AA=E9=80=9A=E8=BF=87=E6=B5=8B?= =?UTF-8?q?=E8=AF=95=E6=98=BE=E7=A4=BA=E7=9A=84=E5=88=9D=E5=A7=8B=E5=8C=96?= =?UTF-8?q?=EF=BC=8C=E4=BB=A5=E5=8F=8A=E4=BF=AE=E6=94=B9=E6=97=B6=E7=9A=84?= =?UTF-8?q?=E7=BB=93=E6=9E=9C=E7=9A=84=E5=AD=98=E5=82=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/homework_common_controller.rb | 4 +++- app/models/homework_test.rb | 2 +- .../_homework_detail_programing_form.html.erb | 12 ++++++++++-- db/migrate/20150801034945_change_result_default.rb | 9 +++++++++ db/schema.rb | 8 ++++---- 5 files changed, 27 insertions(+), 8 deletions(-) create mode 100644 db/migrate/20150801034945_change_result_default.rb diff --git a/app/controllers/homework_common_controller.rb b/app/controllers/homework_common_controller.rb index e3424707f..6f2ecef0b 100644 --- a/app/controllers/homework_common_controller.rb +++ b/app/controllers/homework_common_controller.rb @@ -223,17 +223,19 @@ class HomeworkCommonController < ApplicationController homework_test = HomeworkTest.find id homework_test.destroy if homework_test end - if params[:input] && params[:output] + if params[:input] && params[:output] && params[:result] params[:input].each do |k,v| if params[:output].include? k homework_test = HomeworkTest.find_by_id k if homework_test #已存在的测试,修改 homework_test.input = v homework_test.output = params[:output][k] + homework_test.result = params[:result][k] else #不存在的测试,增加 homework_test = HomeworkTest.new homework_test.input = v homework_test.output = params[:output][k] + homework_test.result = params[:result][k] homework_test.homework_common = @homework end homework_test.save diff --git a/app/models/homework_test.rb b/app/models/homework_test.rb index 4ed290ecd..df2848194 100644 --- a/app/models/homework_test.rb +++ b/app/models/homework_test.rb @@ -1,5 +1,5 @@ class HomeworkTest < ActiveRecord::Base - attr_accessible :input, :output, :homework_common_id + attr_accessible :input, :output, :homework_common_id,:result,:error_msg belongs_to :homework_common has_many :student_work_test diff --git a/app/views/homework_common/_homework_detail_programing_form.html.erb b/app/views/homework_common/_homework_detail_programing_form.html.erb index 7c66df057..22ca4cac7 100644 --- a/app/views/homework_common/_homework_detail_programing_form.html.erb +++ b/app/views/homework_common/_homework_detail_programing_form.html.erb @@ -96,8 +96,16 @@
  • - 测试 - + <% if homework_test.result && !homework_test.result.to_s.empty?%> + <% if homework_test.result == 0%> + 成功 + <% else%> + 错误 + <% end%> + <% else%> + 测试 + <% end%> +
  • diff --git a/db/migrate/20150801034945_change_result_default.rb b/db/migrate/20150801034945_change_result_default.rb new file mode 100644 index 000000000..1f629aa45 --- /dev/null +++ b/db/migrate/20150801034945_change_result_default.rb @@ -0,0 +1,9 @@ +class ChangeResultDefault < ActiveRecord::Migration + def up + change_column :homework_tests,:result,:integer,:default => nil + end + + def down + change_column :homework_tests,:result,:integer,:default => 0 + end +end diff --git a/db/schema.rb b/db/schema.rb index 29aeb1f16..30ca29d12 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended to check this file into your version control system. -ActiveRecord::Schema.define(:version => 20150730130816) do +ActiveRecord::Schema.define(:version => 20150801034945) do create_table "activities", :force => true do |t| t.integer "act_id", :null => false @@ -632,9 +632,9 @@ ActiveRecord::Schema.define(:version => 20150730130816) do t.text "input" t.text "output" t.integer "homework_common_id" - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false - t.integer "result", :default => 0 + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false + t.integer "result" t.text "error_msg" end