From 4166c2300b7d55dca15f9bfcd2f3d5a54c4c1fe6 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Thu, 2 Jan 2020 14:31:58 +0800 Subject: [PATCH] =?UTF-8?q?oj=E4=B8=8E=E9=A2=98=E5=BA=93=E5=85=B3=E8=81=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/hacks_controller.rb | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/app/controllers/hacks_controller.rb b/app/controllers/hacks_controller.rb index 84c24a6d9..2b4c1e847 100644 --- a/app/controllers/hacks_controller.rb +++ b/app/controllers/hacks_controller.rb @@ -61,7 +61,7 @@ class HacksController < ApplicationController hack_codes = hack.hack_codes.new(hack_code_params) hack_codes.modify_time = Time.now hack_codes.save! - new_item_params = item_params.merge({container: hack_codes, item_type: 'PROGRAM'}) + new_item_params = item_params.merge({container: hack, item_type: 'PROGRAM', difficulty: params[:difficult], user_id: current_user.id}) ItemBank.create!(new_item_params) end render_ok({identifier: hack.identifier}) @@ -92,6 +92,12 @@ class HacksController < ApplicationController @hack.hack_codes.first.update_attributes!(code_params) @hack.tag_discipline_containers.create!(tag_params) if tag_params @hack.tag_discipline_containers.where.not(tag_discipline_id: params[:tags]).destroy_all + + # 更新题库相关记录 + if @hack.item_bank.present? + update_item_params = item_params.merge({difficulty: params[:difficult]}) + @hack.item_bank.update!(update_item_params) + end end render_ok rescue Exception => e @@ -192,7 +198,7 @@ class HacksController < ApplicationController end def item_params - params.require(:hack).permit(:name, :difficult, :sub_discipline_id) + params.require(:hack).permit(:name, :sub_discipline_id) end def hack_sets_params