From 7833d10caee5845da43cb3e7c859aeec10294d0d Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Mon, 24 Jun 2019 10:01:15 +0800 Subject: [PATCH] =?UTF-8?q?=E6=AF=95=E4=B8=9A=E8=AE=BE=E8=AE=A1=E7=9A=84?= =?UTF-8?q?=E5=8B=BE=E9=80=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/courses_controller.rb | 2 +- app/models/course.rb | 2 +- app/models/course_module.rb | 1 + app/views/courses/index.json.jbuilder | 2 +- app/views/users/courses/shared/_course.json.jbuilder | 2 +- 5 files changed, 5 insertions(+), 4 deletions(-) diff --git a/app/controllers/courses_controller.rb b/app/controllers/courses_controller.rb index b76673945..01ce1f6e8 100644 --- a/app/controllers/courses_controller.rb +++ b/app/controllers/courses_controller.rb @@ -913,7 +913,7 @@ class CoursesController < ApplicationController def left_banner @user = current_user @is_teacher = @user.teacher_of_course?(@course) - @course_modules = @course.course_modules.where.not(module_type: "activity").where(hidden: 0) + @course_modules = @course.course_modules.where(hidden: 0) @hidden_modules = @course.course_modules.where(hidden: 1) @second_category_type = ["shixun_homework", "graduation", "attachment", "board", "course_group"] end diff --git a/app/models/course.rb b/app/models/course.rb index a2f5add51..7729a2650 100644 --- a/app/models/course.rb +++ b/app/models/course.rb @@ -7,7 +7,7 @@ class Course < ApplicationRecord has_many :course_infos, dependent: :destroy # 课堂左侧导航栏的模块 - has_many :course_modules, -> {where hidden: 0}, dependent: :destroy + has_many :course_modules, dependent: :destroy has_many :board_course_modules, -> { board_module }, class_name: "CourseModule" has_many :attachment_course_modules, -> { attachment_module }, class_name: "CourseModule" has_many :common_course_modules, -> { common_homework_module }, class_name: "CourseModule" diff --git a/app/models/course_module.rb b/app/models/course_module.rb index 7b96a044f..641c70425 100644 --- a/app/models/course_module.rb +++ b/app/models/course_module.rb @@ -7,6 +7,7 @@ class CourseModule < ApplicationRecord validates :module_name, length: { maximum: 20 } + scope :not_hidden, -> { where(hidden: 0) } scope :graduation_module, -> { where(module_type: "graduation") } scope :graduation_module_not_hidden, -> { graduation_module.where(hidden: 0) } scope :board_module, -> { where(module_type: 'board') } diff --git a/app/views/courses/index.json.jbuilder b/app/views/courses/index.json.jbuilder index 1993851e8..5a128a0b7 100644 --- a/app/views/courses/index.json.jbuilder +++ b/app/views/courses/index.json.jbuilder @@ -12,7 +12,7 @@ json.courses do json.is_public course.is_public json.is_accessible course.is_public == 1 || @user.course_identity(course) < Course::NORMAL json.is_end course.is_end - json.first_category_url module_url(course.course_modules.first, course) + json.first_category_url module_url(course.course_modules.not_hidden.first, course) end end json.courses_count @courses_count diff --git a/app/views/users/courses/shared/_course.json.jbuilder b/app/views/users/courses/shared/_course.json.jbuilder index e5823212e..629f47264 100644 --- a/app/views/users/courses/shared/_course.json.jbuilder +++ b/app/views/users/courses/shared/_course.json.jbuilder @@ -4,7 +4,7 @@ json.members_count course.members_count json.homework_commons_count course.homework_commons_count json.attachments_count course.attachments.count -json.first_category_url module_url(course.course_modules.where.not(module_type: "activity").where(hidden: 0).order(position: :desc).first, course) +json.first_category_url module_url(course.course_modules.where(hidden: 0).order(position: :desc).first, course) json.is_public course.is_public json.can_visited observed_logged_user? || course.can_visited?