|
|
|
@ -48,20 +48,16 @@ class HacksController < ApplicationController
|
|
|
|
|
hack = Hack.new(hack_params)
|
|
|
|
|
hack.user_id = current_user.id
|
|
|
|
|
hack.identifier = generate_identifier Hack, 8
|
|
|
|
|
tag_params =
|
|
|
|
|
params[:tags].each do |tag|
|
|
|
|
|
{tag_discipline_id: tag}
|
|
|
|
|
end
|
|
|
|
|
tag_params = params[:tags].map{|tag| {tag_discipline_id: tag}}
|
|
|
|
|
ActiveRecord::Base.transaction do
|
|
|
|
|
hack.save!
|
|
|
|
|
# 创建测试集与代码
|
|
|
|
|
hack.hack_sets.create!(hack_sets_params)
|
|
|
|
|
# 新建知识点
|
|
|
|
|
hack.tag_discipline_containers.create!(tag_params) if tag_params
|
|
|
|
|
hack.tag_discipline_containers.create!(tag_params) if tag_params.present?
|
|
|
|
|
hack_codes = hack.hack_codes.new(hack_code_params)
|
|
|
|
|
hack_codes.modify_time = Time.now
|
|
|
|
|
hack_codes.save!
|
|
|
|
|
logger.info("#############hack_codes:#{hack_codes.id}")
|
|
|
|
|
new_item_params = item_params.merge(container: hack, item_type: 'PROGRAM', difficulty: params[:hack][:difficult], user_id: current_user.id)
|
|
|
|
|
ItemBank.create!(new_item_params)
|
|
|
|
|
end
|
|
|
|
@ -77,10 +73,7 @@ class HacksController < ApplicationController
|
|
|
|
|
# 知识点
|
|
|
|
|
tag_discipline_ids = @hack.tag_discipline_containers.pluck(:tag_discipline_id)
|
|
|
|
|
new_tag_ids = params[:tags].to_a - tag_discipline_ids
|
|
|
|
|
tag_params =
|
|
|
|
|
new_tag_ids.each do |tag|
|
|
|
|
|
{tag_discipline_id: tag}
|
|
|
|
|
end
|
|
|
|
|
tag_params = params[:tags].map{|tag| {tag_discipline_id: tag}}
|
|
|
|
|
ActiveRecord::Base.transaction do
|
|
|
|
|
@hack.update_attributes!(hack_params)
|
|
|
|
|
set_ids = @hack.hack_sets.pluck(:id)
|
|
|
|
|