|
|
@ -230,11 +230,16 @@ class ChallengesController < ApplicationController
|
|
|
|
def crud_answer
|
|
|
|
def crud_answer
|
|
|
|
raise '参考答案不能为空' if params[:challenge_answer].empty?
|
|
|
|
raise '参考答案不能为空' if params[:challenge_answer].empty?
|
|
|
|
raise '占比之和必须为100%' if params[:challenge_answer].map{|a| a[:score]}.sum != 100
|
|
|
|
raise '占比之和必须为100%' if params[:challenge_answer].map{|a| a[:score]}.sum != 100
|
|
|
|
@challenge.challenge_answers.destroy_all if @challenge.challenge_answers
|
|
|
|
ActiveRecord::Base.transaction do
|
|
|
|
params[:challenge_answer].each_with_index do |answer, index|
|
|
|
|
@challenge.challenge_answers.destroy_all if @challenge.challenge_answers
|
|
|
|
ChallengeAnswer.create(name: answer[:name], contents: answer[:contents],
|
|
|
|
params[:challenge_answer].each_with_index do |answer, index|
|
|
|
|
level: index+1, score: answer[:score], challenge_id: @challenge.id)
|
|
|
|
# 内容为空不保存
|
|
|
|
|
|
|
|
next if answer[:contents].blank?
|
|
|
|
|
|
|
|
ChallengeAnswer.create(name: answer[:name], contents: answer[:contents],
|
|
|
|
|
|
|
|
level: index+1, score: answer[:score], challenge_id: @challenge.id)
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
# 查看参考答案接口
|
|
|
|
# 查看参考答案接口
|
|
|
|