diff --git a/app/controllers/homework_commons_controller.rb b/app/controllers/homework_commons_controller.rb index adf0dc6bf..faea30242 100644 --- a/app/controllers/homework_commons_controller.rb +++ b/app/controllers/homework_commons_controller.rb @@ -359,6 +359,9 @@ class HomeworkCommonsController < ApplicationController def new tip_exception("type参数有误") if params[:type].blank? || ![1, 3].include?(params[:type].to_i) @homework_type = params[:type].to_i + module_type = params[:type].to_i == 1 ? "common_homework" : "group_homework" + @main_category = @course.course_modules.find_by(module_type: module_type) + @category = @main_category.course_second_categories.find_by(id: params[:category]) if params[:category].present? end def create @@ -409,7 +412,12 @@ class HomeworkCommonsController < ApplicationController end def edit - + if @homework.course_second_category_id == 0 + module_type = @homework.homework_type == "normal" ? "common_homework" : "group_homework" + @main_category = @course.course_modules.find_by(module_type: module_type) + else + @category = @homework.course_second_category + end end def update diff --git a/app/views/homework_commons/edit.json.jbuilder b/app/views/homework_commons/edit.json.jbuilder index 49dc11dd8..d2eb865ac 100644 --- a/app/views/homework_commons/edit.json.jbuilder +++ b/app/views/homework_commons/edit.json.jbuilder @@ -1,6 +1,16 @@ json.course_id @course.id json.course_name @course.name -json.category @homework.category_info +# json.category @homework.category_info + +json.category do + if @category.present? + json.category_id @category.id + json.category_name @category.name + else + json.category_id @main_category&.id + json.category_name @main_category&.module_name + end +end json.(@homework, :id, :name, :description, :reference_answer) diff --git a/app/views/homework_commons/new.json.jbuilder b/app/views/homework_commons/new.json.jbuilder index 82a5d78fa..9a703d40f 100644 --- a/app/views/homework_commons/new.json.jbuilder +++ b/app/views/homework_commons/new.json.jbuilder @@ -1,3 +1,11 @@ json.course_id @course.id json.course_name @course.name -json.category @course.category_info(@homework_type == 1 ? "common_homework" : "group_homework") \ No newline at end of file +json.category do + if @category.present? + json.category_id @category.id + json.category_name @category.name + else + json.category_id @main_category&.id + json.category_name @main_category&.module_name + end +end \ No newline at end of file