diff --git a/app/models/homework_common.rb b/app/models/homework_common.rb index a6a919981..58a420581 100644 --- a/app/models/homework_common.rb +++ b/app/models/homework_common.rb @@ -69,17 +69,18 @@ class HomeworkCommon < ApplicationRecord # 作业对应的子目录/父目录名称 def category_info - case self.homework_type - when 'normal' - {category_id: course.common_course_modules.first.try(:id), category_name: course.common_course_modules.first.try(:module_name), main: 1} - when 'group' - {category_id: course.group_course_modules.first.try(:id), category_name: course.group_course_modules.first.try(:module_name), main: 1} - when 'practice' - if self.course_second_category.present? - {category_id: self.course_second_category.try(:id), category_name: self.course_second_category.try(:name), main: 0} - else - {category_id: course.shixun_course_modules.take.try(:id), category_name: course.shixun_course_modules.take.try(:module_name), main: 1} - end + if self.course_second_category.present? + {category_id: self.course_second_category.try(:id), category_name: self.course_second_category.try(:name), main: 0} + else + course_module = case homework_type + when 'normal' + course.common_course_modules.take + when 'group' + course.group_course_modules.take + when 'practice' + course.shixun_course_modules.take + end + {category_id: course_module.try(:id), category_name: course_module.try(:module_name), main: 1} end end