选择题查看实训答案的问题

dev_course
daiao 6 years ago
parent 716b5af39f
commit b6ccd6562c

@ -225,18 +225,8 @@ class GamesController < ApplicationController
# GET: /tasks/:identifier/get_answer_info
# 0 直接查看答案, 1 查看答案弹框, 2 答案详情弹框
def get_answer_info
@challenge = @game.challenge
if @challenge.st == 0
@challenge_answers = @challenge.challenge_answers
else
result = []
@challenge.challenge_chooses.each do |choose|
result << {:position => choose.position, :answer => (choose.answer.blank? ? choose.standard_answer : choose.answer)}
end
@challenge_answers = result
end
challenge = @game.challenge
@challenge_answers = challenge.challenge_answers
# 平台已认证的老师需要控制
@power = (@identity < User::EDU_GAME_MANAGER)
if !@power
@ -259,14 +249,22 @@ class GamesController < ApplicationController
# 解锁答案
# GET: /tasks/:identifier/get_answer_info?answer_id=?
def unlock_answer
@answer = ChallengeAnswer.find(params[:answer_id])
challenge = @answer.challenge
# 解锁需要本层级的答案是否需要扣分
points = challenge.challenge_answers.where(level: @game.answer_open+1..@answer.level).sum(:score)
deduct_score = ((points / 100.0) * challenge.score).to_i
uid_logger("############金币数目: #{current_user.grade}")
unless current_user.grade.to_i - deduct_score > 0
tip_exception("您没有足够的金币")
@challenge = @game.challenge
if @challenge.st == 0
@answer = ChallengeAnswer.find(params[:answer_id])
challenge = @answer.challenge
# 解锁需要本层级的答案是否需要扣分
points = challenge.challenge_answers.where(level: @game.answer_open+1..@answer.level).sum(:score)
deduct_score = ((points / 100.0) * challenge.score).to_i
uid_logger("############金币数目: #{current_user.grade}")
unless current_user.grade.to_i - deduct_score > 0
tip_exception("您没有足够的金币")
end
else
@answer = []
@challenge.challenge_chooses.each do |choose|
@answer << {:position => choose.position, :answer => (choose.answer.blank? ? choose.standard_answer : choose.answer)}
end
end
ActiveRecord::Base.transaction do

@ -1,26 +1,18 @@
index = 0
json.status 3
# st: 0 实践题 1 选择题
if @challenge.st == 0
json.message do
json.array! @challenge_answers do |answer|
index += 1
json.answer_id answer.id
json.answer_name answer.name
json.answer_score answer.score
# 高层级不给答案
if @power || @game.answer_open >= index
json.answer_contents answer.contents
end
end
end
else
json.message do
json.array! @challenge_answers do |answer|
json.position answer[:postion]
json.answer_contents answer[:answer]
json.message do
json.array! @challenge_answers do |answer|
index += 1
json.answer_id answer.id
json.answer_name answer.name
json.answer_score answer.score
# 高层级不给答案
if @power || @game.answer_open >= index
json.answer_contents answer.contents
end
end
end

@ -1 +1,5 @@
json.contents @answer.contents
if @challenge.st == 0
json.contents @answer.contents
else
json.contents @answer
end

Loading…
Cancel
Save