修改编程作业时,对已通过测试、未通过测试显示的初始化,以及修改时的结果的存储
This commit is contained in:
parent
cbbc93acbd
commit
f5cfd7258d
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -96,8 +96,16 @@
|
|||
<li>
|
||||
<a class="icon_add ml10 " href="javascript:void(0);" title="添加测试" onclick="add_programing_test($(this).parent().parent())"></a>
|
||||
<a class="icon_remove" href="javascript:void(0);" title="删除测试" onclick="remove_programing_test($(this).parent().parent())"></a>
|
||||
<% if homework_test.result && !homework_test.result.to_s.empty?%>
|
||||
<% if homework_test.result == 0%>
|
||||
<a class="green_btn fl ml5 mt1 programing_test" onclick="programing_test('<%= homework_test.id%>')" id="test_send_<%= homework_test.id%>">成功</a>
|
||||
<% else%>
|
||||
<a class="red_btn fl ml5 mt1 programing_test" onclick="programing_test('<%= homework_test.id%>')" id="test_send_<%= homework_test.id%>">错误</a>
|
||||
<% end%>
|
||||
<% else%>
|
||||
<a class="blue_btn fl ml5 mt1 programing_test" onclick="programing_test('<%= homework_test.id%>')" id="test_send_<%= homework_test.id%>">测试</a>
|
||||
<input type="hidden" id="test_result_<%= homework_test.id%>" name="result[<%= homework_test.id%>]" />
|
||||
<% end%>
|
||||
<input type="hidden" id="test_result_<%= homework_test.id%>" name="result[<%= homework_test.id%>]" value="<%= homework_test.result%>"/>
|
||||
</li>
|
||||
<div class="cl"></div>
|
||||
</div>
|
||||
|
|
|
@ -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
|
|
@ -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
|
||||
|
@ -634,7 +634,7 @@ ActiveRecord::Schema.define(:version => 20150730130816) do
|
|||
t.integer "homework_common_id"
|
||||
t.datetime "created_at", :null => false
|
||||
t.datetime "updated_at", :null => false
|
||||
t.integer "result", :default => 0
|
||||
t.integer "result"
|
||||
t.text "error_msg"
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in New Issue