删除插入问题

This commit is contained in:
huang 2015-11-20 19:05:39 +08:00
parent a3122a9a2c
commit da55b00da7
1 changed files with 19 additions and 5 deletions

View File

@ -269,11 +269,23 @@ class ExerciseController < ApplicationController
def delete_exercise_question
@exercise_question = ExerciseQuestion.find params[:exercise_question]
@exercise = @exercise_question.exercise
exercise_questions = @exercise.exercise_questions.where("question_number > #{@exercise_question.question_number}")
exercise_questions.each do |question|
question.question_number -= 1
question.save
if @exercise_question.question_type == 1
ExerciseQuestion.where("question_number>? and question_type=?",params[:quest_num].to_i, 1).update_all(" question_number = question_number - 1")
#@exercise.exercise_questions.where("question_number > #{params[:quest_num].to_i} and question_type == 1").update_all(" question_number = question_number + 1")
elsif @exercise_question.question_type == 2
ExerciseQuestion.where("question_number>? and question_type=?",params[:quest_num].to_i, 2).update_all(" question_number = question_number - 1")
else
ExerciseQuestion.where("question_number>? and question_type=?",params[:quest_num].to_i, 3).update_all(" question_number = question_number - 1")
end
# @exercise_question_num = params[:quest_num].to_i
# @exercise_questions.question_number = params[:quest_num].to_i - 1
#
# exercise_questions = @exercise.exercise_questions.where("question_number > #{@exercise_question.question_number}")
# exercise_questions.each do |question|
# question.question_number -= 1
# question.save
# end
if @exercise_question && @exercise_question.destroy
respond_to do |format|
format.js
@ -568,7 +580,9 @@ class ExerciseController < ApplicationController
exercises = course.exercises.where("exercise_name=?","")
unless exercises.empty?
exercises.each do |exercise|
exercise.destroy
if exercise.exercise_questions.empty?
exercise.destroy
end
end
end
end