diff --git a/app/helpers/courses_helper.rb b/app/helpers/courses_helper.rb index 36eebe4f2..64531a6f4 100644 --- a/app/helpers/courses_helper.rb +++ b/app/helpers/courses_helper.rb @@ -24,7 +24,7 @@ module CoursesHelper def find_excelletn_course keywords, current_course # 获取tag匹配结果ID a_tags = [] - Course.where("is_excellent =? and is_public =?", 1, 1).includes(:tags).each do |ec| + Course.where("is_excellent =? and is_public =?", 1, 1).each do |ec| if ec.tags.any?{|value| current_course.name.include?(value.to_s)} a_tags << ec.id end diff --git a/app/views/layouts/new_base_user.html.erb b/app/views/layouts/new_base_user.html.erb index a613d8984..6096b84cd 100644 --- a/app/views/layouts/new_base_user.html.erb +++ b/app/views/layouts/new_base_user.html.erb @@ -204,12 +204,18 @@ <% end%> <% end%> - <% course_order_ids = "(" + + <% if @user.courses.visible.count > 0 + course_order_ids = "(" + CourseActivity.find_by_sql("SELECT c.course_id, updated_at FROM (SELECT ca.course_id, MAX(ca.updated_at) AS updated_at FROM course_activities ca WHERE ca.course_id IN (" + @user.courses.visible.select('courses.id').map{|c| c.id}.join(',') + ") GROUP BY ca.course_id) AS c - ORDER BY c.updated_at DESC limit 5").map {|c| c.course_id}.join(",") + ")"%> - <% courses = Course.where("id in #{course_order_ids}")%> + ORDER BY c.updated_at DESC limit 5").map {|c| c.course_id}.join(",") + ")" + courses = Course.where("id in #{course_order_ids}") + else + courses = [] + + end + %> <%# courses = @user.courses.visible.where("is_delete =?", 0).select("courses.*,(SELECT MAX(updated_at) FROM `course_activities` WHERE course_activities.course_id = courses.id) AS a").order("a desc").limit(5) %>