|
|
@ -234,6 +234,9 @@ class ChallengesController < ApplicationController
|
|
|
|
# {...}, ...]
|
|
|
|
# {...}, ...]
|
|
|
|
#}
|
|
|
|
#}
|
|
|
|
def crud_answer
|
|
|
|
def crud_answer
|
|
|
|
|
|
|
|
if @challenge.challenge_answers && params[:challenge_answer].empty?
|
|
|
|
|
|
|
|
@challenge.challenge_answers.destroy_all
|
|
|
|
|
|
|
|
else
|
|
|
|
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
|
|
|
|
ActiveRecord::Base.transaction do
|
|
|
|
ActiveRecord::Base.transaction do
|
|
|
@ -245,7 +248,7 @@ class ChallengesController < ApplicationController
|
|
|
|
level: index+1, score: answer[:score], challenge_id: @challenge.id)
|
|
|
|
level: index+1, score: answer[:score], challenge_id: @challenge.id)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
# 查看参考答案接口
|
|
|
|
# 查看参考答案接口
|
|
|
|