管理员界面中的学校列表支持按用户数排序
This commit is contained in:
parent
e61cf5dd4f
commit
f78595bbbb
|
@ -599,8 +599,19 @@ class AdminController < ApplicationController
|
||||||
|
|
||||||
#学校列表
|
#学校列表
|
||||||
def schools
|
def schools
|
||||||
|
@order = ""
|
||||||
|
@sort = ""
|
||||||
@schools = School.find_by_sql("SELECT * FROM schools ORDER BY created_at DESC")
|
@schools = School.find_by_sql("SELECT * FROM schools ORDER BY created_at DESC")
|
||||||
|
if params[:sort] && (params[:order] == 'num')
|
||||||
|
@order = params[:order]
|
||||||
|
@sort = params[:sort]
|
||||||
|
@schools.each do |school|
|
||||||
|
count = UserExtensions.where("school_id = #{school.id} or occupation = '#{school.name}'").count
|
||||||
|
school[:infocount] = count.to_i
|
||||||
|
end
|
||||||
|
@sort == 'asc' ? (@schools = @schools.sort{|x,y| x[:infocount] <=> y[:infocount] }) : (@schools = @schools.sort{|x,y| y[:infocount] <=> x[:infocount]})
|
||||||
|
end
|
||||||
|
|
||||||
@school_count = @schools.count
|
@school_count = @schools.count
|
||||||
|
|
||||||
@school_pages = Paginator.new @school_count, 30, params['page'] || 1
|
@school_pages = Paginator.new @school_count, 30, params['page'] || 1
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
module SchoolHelper
|
module SchoolHelper
|
||||||
def schoolMember_num school
|
def schoolMember_num school
|
||||||
count = student_num(school) + teacher_num(school)
|
count = UserExtensions.where("school_id = #{school.id} or occupation = '#{school.name}'").count
|
||||||
count.to_s
|
count.to_s
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -20,8 +20,8 @@
|
||||||
<th style="width: 100px;">
|
<th style="width: 100px;">
|
||||||
学校名称
|
学校名称
|
||||||
</th>
|
</th>
|
||||||
<th style="width: 35px;">
|
<th style="width: 35px;" class = "<%= @order == 'num' ? (@sort == 'desc' ? 'st_up' : (@sort == 'asc' ? 'st_down' : '')) : '' %>">
|
||||||
用户数
|
<%= link_to '用户数', admin_schools_path(:sort=> @sort == "desc" ? 'asc' : 'desc', :order => 'num') %>
|
||||||
</th>
|
</th>
|
||||||
<th style="width: 90px;">
|
<th style="width: 90px;">
|
||||||
创建时间
|
创建时间
|
||||||
|
|
Loading…
Reference in New Issue