From 7f3fcb7d019fb74907cf91aa94b45cc5af0d71bb Mon Sep 17 00:00:00 2001 From: cxt Date: Fri, 15 Apr 2016 14:54:17 +0800 Subject: [PATCH] =?UTF-8?q?=E7=B2=BE=E5=93=81=E8=AF=BE=E7=A8=8B=E5=88=97?= =?UTF-8?q?=E8=A1=A8=E4=B8=AD=E7=9A=84=E5=85=A8=E9=83=A8=E8=AF=BE=E7=A8=8B?= =?UTF-8?q?=E5=8F=AF=E7=82=B9=E5=87=BB=E5=8A=A8=E6=80=81=E6=95=B0=E6=8E=92?= =?UTF-8?q?=E5=BA=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/admin_controller.rb | 15 ++++++++++++--- app/views/admin/excellent_all_courses.html.erb | 4 ++-- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/app/controllers/admin_controller.rb b/app/controllers/admin_controller.rb index 81407d95d..99732fc6b 100644 --- a/app/controllers/admin_controller.rb +++ b/app/controllers/admin_controller.rb @@ -65,9 +65,18 @@ class AdminController < ApplicationController #精品课程下的全部课程 def excellent_all_courses - @name = params[:name] - @courses = Course.like(@name).order('created_at desc') - @courses = paginateHelper @courses,30 + name = params[:name] + @order = "" + if params[:order] == 'asc' + courses = Course.find_by_sql("SELECT c.*,count(c.id) FROM courses c,course_activities ca WHERE c.id = ca.course_id AND c.name like '%#{name}%' GROUP BY c.id ORDER BY count(c.id) asc, c.id desc") + @order = params[:order] + elsif params[:order] == 'desc' + courses = Course.find_by_sql("SELECT c.*,count(c.id) FROM courses c,course_activities ca WHERE c.id = ca.course_id AND c.name like '%#{name}%' GROUP BY c.id ORDER BY count(c.id) DESC, c.id desc") + @order = params[:order] + else + courses = Course.like(name).order('created_at desc') + end + @courses = paginateHelper courses,30 @page = (params['page'] || 1).to_i - 1 respond_to do |format| format.html diff --git a/app/views/admin/excellent_all_courses.html.erb b/app/views/admin/excellent_all_courses.html.erb index 7554885a9..86e4556f9 100644 --- a/app/views/admin/excellent_all_courses.html.erb +++ b/app/views/admin/excellent_all_courses.html.erb @@ -48,8 +48,8 @@ 帖子数 - - 动态数 + + <%=link_to '动态数', excellent_all_courses_path(:order=> @order == "desc" ? 'asc' : 'desc') %>