diff --git a/app/controllers/admin_controller.rb b/app/controllers/admin_controller.rb index f663bc272..d1d9fbdf5 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 @@