增删测试集

chromesetting
daiao 5 years ago
parent 4b70bf6ccd
commit a626f9ce5d

@ -1,8 +1,8 @@
class HacksController < ApplicationController class HacksController < ApplicationController
before_action :require_login, except: [:index] before_action :require_login, except: [:index]
before_action :require_teacher_identity, only: [:create, :edit, :update] before_action :require_teacher_identity, only: [:create, :update_set]
before_action :require_auth_identity, only: [:update, :edit, :publish] before_action :require_auth_identity, only: [:update, :edit, :publish, :update_set, :delete_set]
before_action :find_hack, only: [:edit, :update, :publish, :start] before_action :find_hack, only: [:edit, :update, :publish, :start, :update_set, :delete_set]
# 开启编程,如果第一次开启,创建一条记录,如果已经开启过的话,直接返回标识即可 # 开启编程,如果第一次开启,创建一条记录,如果已经开启过的话,直接返回标识即可
def start def start
@ -75,6 +75,20 @@ class HacksController < ApplicationController
end end
end end
# 更新测试集接口
def update_set
set = @hack.hack_sets.find_by(id: params[:id])
set.update_attributes!(hack_set_params)
render_ok
end
# 单独删除测试集
def delete_set
set = @hack.hack_sets.find_by(id: params[:id])
set.destroy!
render_ok
end
# 发布功能 # 发布功能
def publish def publish
@hack.update_attribute(:status, 1) @hack.update_attribute(:status, 1)
@ -119,6 +133,10 @@ class HacksController < ApplicationController
params.permit(hack_sets: [:input, :output, :position])[:hack_sets] params.permit(hack_sets: [:input, :output, :position])[:hack_sets]
end end
def hack_set_params
params.require(:hack_set).permit(:id, :input, :output, :position)
end
def hack_code_params def hack_code_params
params.require(:hack_codes).permit(:code, :language) params.require(:hack_codes).permit(:code, :language)
end end

@ -1,4 +1,6 @@
class HackSet < ApplicationRecord class HackSet < ApplicationRecord
validates :input, presence: { message: "测试集输入不能为空" }
validates :output, uniqueness: { message: "测试集输出不能为空" }
# 编程题测试集 # 编程题测试集
belongs_to :hack belongs_to :hack
end end

@ -43,6 +43,8 @@ Rails.application.routes.draw do
post :publish post :publish
get :start get :start
get :result get :result
post :update_set
delete :delete_set
end end
resources :comments do resources :comments do

Loading…
Cancel
Save