修改编程作业发送

This commit is contained in:
sw 2015-07-22 17:47:48 +08:00
parent ffee6d27a6
commit c1824a6db0
1 changed files with 19 additions and 0 deletions

View File

@ -236,6 +236,25 @@ class HomeworkCommonController < ApplicationController
end
end
end
#发送修改作业的请求
question = {title:@homework.name,content:@homework.description}
question[:input] = []
question[:output] = []
@homework.homework_tests.each do |test|
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)
homework_detail_programing.question_id = result["id"] if result["status"] && result["status"] == 0
end
@homework.save_attachments(params[:attachments])