This commit is contained in:
guange 2015-08-26 20:23:17 +08:00
parent ad0b14b768
commit 3ae4d01284
2 changed files with 44 additions and 26 deletions

View File

@ -115,23 +115,16 @@ class HomeworkCommonController < ApplicationController
end
end
# uri = URI('http://test.gitlab.trustie.net/api/questions.json')
# req = Net::HTTP::Post.new(uri, initheader = {'Content-Type' =>'application/json'})
# req.body = question.to_json
# res = Net::HTTP.start(uri.hostname, uri.port) do |http|
# http.request(req)
# uri = URI('http://192.168.80.21:8080/api/questions.json')
# body = question.to_json
# res = Net::HTTP.new(uri.host, uri.port).start do |client|
# request = Net::HTTP::Post.new(uri.path)
# request.body = body
# request["Content-Type"] = "application/json"
# client.request(request)
# end
uri = URI('http://192.168.80.21:8080/api/questions.json')
body = question.to_json
res = Net::HTTP.new(uri.host, uri.port).start do |client|
request = Net::HTTP::Post.new(uri.path)
request.body = body
request["Content-Type"] = "application/json"
client.request(request)
end
result = JSON.parse(res.body)
homework_detail_programing.question_id = result["id"] if result["status"] && result["status"] == 0
# result = JSON.parse(res.body)
# homework_detail_programing.question_id = result["id"] if result["status"] && result["status"] == 0
homework.homework_detail_programing = homework_detail_programing
else
@ -254,15 +247,15 @@ class HomeworkCommonController < ApplicationController
question[:input] << test.input
question[:output] << test.output
end
uri = URI("http://192.168.80.21:8080/api/questions/#{@homework_detail_programing.question_id}.json")
body = question.to_json
res = Net::HTTP.new(uri.host, uri.port).start do |client|
request = Net::HTTP::Put.new(uri.path)
request.body = body
request["Content-Type"] = "application/json"
client.request(request)
end
result = JSON.parse(res.body)
# uri = URI("http://192.168.80.21:8080/api/questions/#{@homework_detail_programing.question_id}.json")
# body = question.to_json
# res = Net::HTTP.new(uri.host, uri.port).start do |client|
# request = Net::HTTP::Put.new(uri.path)
# request.body = body
# request["Content-Type"] = "application/json"
# client.request(request)
# end
# result = JSON.parse(res.body)
end
@homework.save_attachments(params[:attachments])
@ -406,4 +399,4 @@ class HomeworkCommonController < ApplicationController
student_works += student_works
student_works[index + 1 .. index + n]
end
end
end

View File

@ -14,4 +14,29 @@
<%= link_to '取消',homework_common_index_path(:course => @course.id),:class => 'grey_btn fl'%>
<% end%>
</div><!--hwork_new end-->
<div class="hwork_new" id="hwork_new">
<%= form_for("new_homework_common",:url => next_step_homework_common_index_path) do |f|%>
<input type="hidden" name="course" value="<%= @course.id%>">
<h3 class="c_blue f16 mb10">
请选择将要发布的作业类型
</h3>
<input type="radio" class="mb10 fl" name="homework_common_type" value="1" id="homework_detail_manual_radio" checked/>
<span class="ml5 fl">
人工评分的作业(支持匿名互评、灵活设置评分比例)
</span>
<div class="cl"></div>
<input type="radio" class="mb20 fl" name="homework_common_type" value="2" id="homework_detail_programing_radio"/>
<span class="ml5 fl">
自动评测的编程作业支持C/C++程序的自动评分)
</span>
<div class="cl"></div>
<a href="javascript:void(0);" class=" orange_btn" onclick="$(this).parent().submit();">
下一步
</a>
<% end%>
</div><!--hwork_new end-->
<div class="cl"></div>