From 05d66f41f9f6031db44d4a50e815b1d199af6b00 Mon Sep 17 00:00:00 2001 From: alan <547533434@qq.com> Date: Fri, 25 Mar 2016 17:07:30 +0800 Subject: [PATCH] fix bug when user don't have courses or projects --- app/views/layouts/new_base_user.html.erb | 25 +++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/app/views/layouts/new_base_user.html.erb b/app/views/layouts/new_base_user.html.erb index a613d8984..682297a5c 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) %>