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