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