48 lines
1.6 KiB
Ruby
48 lines
1.6 KiB
Ruby
class MyshixunsController < ApplicationController
|
|
layout 'base_myshixun'
|
|
skip_before_filter :verify_authenticity_token, :only => [:training_task_status]
|
|
before_filter :require_login, :except => [:training_task_status]
|
|
before_filter :find_myshixun, :only => [:show]
|
|
|
|
# taskId 即返回的game id
|
|
# params [:stauts] 0 表示成功,其它则失败
|
|
# msg 错误信息
|
|
# output 为测试用户编译输出结果
|
|
# myshixun:status 1为完成实训
|
|
def training_task_status
|
|
status = params[:status].to_i
|
|
task_id = params[:taskId]
|
|
outPut = Base64.decode64(params[:outPut]) unless params[:outPut].blank?
|
|
message = Base64.decode64(params[:msg]) unless params[:msg].blank?
|
|
game = Game.find(task_id)
|
|
if status == 0
|
|
myshixun = game.myshixun
|
|
games_count = myshixun.games.count
|
|
if game.stage == games_count
|
|
myshixun.update_attribute(:status, 1)
|
|
end
|
|
game_outputs = Output.create(:code => status, :msg => message, :game_id => task_id, :out_put => outPut)
|
|
game.update_attribute(:status, 2)
|
|
game.update_attribute(:final_score, game.score)
|
|
else
|
|
game_outputs = Output.create(:code => status, :msg => message, :game_id => task_id, :out_put => outPut)
|
|
game.update_attribute(:status, 0)
|
|
end
|
|
render :json => {:data => "success"}
|
|
end
|
|
|
|
def show
|
|
respond_to do |format|
|
|
format.html{redirect_to myshixun_game_path(@myshixun.current_task, :myshixun_id => @myshixun)}
|
|
end
|
|
end
|
|
|
|
private
|
|
# Find myshixun of id params[:id]
|
|
def find_myshixun
|
|
@myshixun = Myshixun.find(params[:id])
|
|
rescue ActiveRecord::RecordNotFound
|
|
render_404
|
|
end
|
|
end
|