From 603d6a4aec5eb8f2489f566b57ee294ba3d5973a Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Mon, 15 Jul 2019 15:50:45 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/courses_controller.rb | 2 +- app/models/user.rb | 7 +------ 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/app/controllers/courses_controller.rb b/app/controllers/courses_controller.rb index 2ecb522a2..1e18b8be6 100644 --- a/app/controllers/courses_controller.rb +++ b/app/controllers/courses_controller.rb @@ -96,7 +96,7 @@ class CoursesController < ApplicationController limit = params[:limit] || 16 @courses = @courses.page(page).per(limit) - @courses = @courses.preload(:school, :course_members, teacher: :user_extension) + @courses = @courses.preload(:school, teacher: :user_extension) end def visits_plus_one diff --git a/app/models/user.rb b/app/models/user.rb index f2ea635c4..26f0fa544 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -323,12 +323,7 @@ class User < ApplicationRecord elsif business? Course::BUSINESS else - role = - if course.course_members.loaded? - course.course_members.find{|member| member.user_id == id && member.is_active == 1}&.role - else - course.course_members.find_by(user_id: id, is_active: 1)&.role - end + role = course.course_members.find_by(user_id: id, is_active: 1)&.role case role when nil then Course::NORMAL when 'CREATOR' then Course::CREATOR