diff --git a/app/controllers/school_controller.rb b/app/controllers/school_controller.rb index 5ba6d836b..ef938b69d 100644 --- a/app/controllers/school_controller.rb +++ b/app/controllers/school_controller.rb @@ -27,6 +27,11 @@ class SchoolController < ApplicationController def upload_logo end + + #获取制定学校开设的课程数 + def course_count school_id + School.find(school_id).courses.count + end def index diff --git a/app/helpers/welcome_helper.rb b/app/helpers/welcome_helper.rb index 53869b9ed..d0b0ee5ad 100644 --- a/app/helpers/welcome_helper.rb +++ b/app/helpers/welcome_helper.rb @@ -105,6 +105,30 @@ module WelcomeHelper # c2 = c2 - c1 # (c1.take(max)+c2).take(sum) end + + #查找所有学校按每个学校开设课程数量降序排序 + #page 分页查询开始条数的编号,从0开始 + #limit 分页查询的数量 + def find_maxmin_course_school page,limit + School.find_by_sql("SELECT *,(SELECT COUNT(*) FROM courses WHERE school_id = schools.id) AS a + FROM schools + ORDER BY a DESC LIMIT #{page},#{limit}") + #School.where(" id IN (SELECT school_id FROM courses GROUP BY school_id)").limit limit; + #School.order("#{School.course_count}").limit(limit).all + #@school = School.all.sort + #@school.each do |s| + # s.courses.count + #end + #result = [] + #@school = School.all.to_ary + #i = 1 + #for i in i < School.count + # j = i - 1 + # for j in j > 0 + # if @school[j].courses.count > + # end + #end + end def find_miracle_project(sum, max_rate) max = sum*(max_rate.to_f/10) diff --git a/app/views/welcome/course.html.erb b/app/views/welcome/course.html.erb index b8b755b58..292e07fbe 100644 --- a/app/views/welcome/course.html.erb +++ b/app/views/welcome/course.html.erb @@ -1,6 +1,6 @@ <%= stylesheet_link_tag 'welcome' %> <%= javascript_include_tag 'welcome' %> -