精品课程列表中的全部课程可点击动态数排序

This commit is contained in:
cxt 2016-04-15 14:54:17 +08:00
parent 143f3f8f9a
commit 7f3fcb7d01
2 changed files with 14 additions and 5 deletions

View File

@ -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

View File

@ -48,8 +48,8 @@
<th style="width: 50px;">
帖子数
</th>
<th style="width: 50px;">
动态数
<th style="width: 50px;" class = "<%= @order == 'desc' ? 'st_up' : (@order == 'asc' ? 'st_down' : '') %>">
<%=link_to '动态数', excellent_all_courses_path(:order=> @order == "desc" ? 'asc' : 'desc') %>
</th>
<th style="width: 40px;">
</tr>