diff --git a/app/controllers/subjects_controller.rb b/app/controllers/subjects_controller.rb index 1f66555f9..77d89c40c 100644 --- a/app/controllers/subjects_controller.rb +++ b/app/controllers/subjects_controller.rb @@ -248,7 +248,7 @@ class SubjectsController < ApplicationController def send_to_course @course = Course.find_by!(id: params[:course_id]) stages = @subject.stages.where(id: @subject.stage_shixuns.where(shixun_id: params[:shixun_ids]).pluck(:stage_id)) - + order_ids = params[:shixun_ids].size > 0 ? params[:shixun_ids].reverse.join(',') : -1 course_module = @course.course_modules.where(module_type: "shixun_homework").first homework_ids = [] @@ -259,7 +259,8 @@ class SubjectsController < ApplicationController CourseSecondCategory.create!(name: stage.name, course_id: @course.id, category_type: "shixun_homework", course_module_id: course_module.id, position: course_module.course_second_categories.count + 1) - stage.shixuns.no_jupyter.where(id: params[:shixun_ids], status: 2).each do |shixun| + shixuns = stage.shixuns.no_jupyter.published.where(id: params[:shixun_ids]).reorder("field(shixuns.id, #{order_ids})") + shixuns.each do |shixun| homework = HomeworksService.new.create_homework shixun, @course, category, current_user homework_ids << homework.id end