From 6051d0797d4018af815c3d45b31a681641451a89 Mon Sep 17 00:00:00 2001 From: sw <939547590@qq.com> Date: Fri, 14 Aug 2015 16:24:43 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AF=BE=E7=A8=8B=E6=90=9C=E7=B4=A2=E7=BB=93?= =?UTF-8?q?=E6=9E=9C=E4=B8=8D=E6=AD=A3=E7=A1=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/courses_controller.rb | 67 ++------------------------- app/views/courses/search.html.erb | 12 ++--- 2 files changed, 11 insertions(+), 68 deletions(-) diff --git a/app/controllers/courses_controller.rb b/app/controllers/courses_controller.rb index 71715035e..29f2e00f4 100644 --- a/app/controllers/courses_controller.rb +++ b/app/controllers/courses_controller.rb @@ -106,74 +106,17 @@ class CoursesController < ApplicationController # 课程搜索 # add by nwb def search - courses_all = Course.all_course - name = params[:name] - if name.blank? - @courses = [] - @courses_all = [] - @course_count = 0 - @course_pages = Paginator.new @course_count, per_page_option, params['page'] + if params[:name].empty? + courses = Course.visible + @courses = paginateHelper courses,10 else - @courses = courses_all.visible - if params[:name].present? - @courses_all = @courses.like(params[:name]) - else - @courses_all = @courses; - end - @course_count = @courses_all.count - @course_pages = Paginator.new @course_count, per_page_option, params['page'] - - # 课程的动态数 - # @course_activity_count=Hash.new - # @courses_all.each do |course| - # @course_activity_count[course.id]=0 - # end - # - # case params[:course_sort_type] - # when '0' - # @courses = @courses_all.order("created_at desc") - # @s_type = 0 - # @courses = @courses.offset(@course_pages.offset).limit(@course_pages.per_page) - # - # @course_activity_count=get_course_activity @courses,@course_activity_count - # - # when '1' - # @courses = @courses_all.order("course_ac_para desc") - # @s_type = 1 - # @courses = @courses.offset(@course_pages.offset).limit(@course_pages.per_page) - # - # @course_activity_count=get_course_activity @courses,@course_activity_count - # - # when '2' - # @courses = @courses_all.order("watchers_count desc") - # @s_type = 2 - # @courses = @courses.offset(@course_pages.offset).limit(@course_pages.per_page) - # - # @course_activity_count=get_course_activity @courses,@course_activity_count - # - # when '3' - # @course_activity_count=get_course_activity @courses_all,@course_activity_count_array - # @courses=handle_course @courses_all,@course_activity_count - # @s_type = 3 - # @courses = @courses[@course_pages.offset, @course_pages.per_page] - # - # else - # @s_type = 0 - # @courses = @courses_all.order("created_at desc") - # @courses = @courses.offset(@course_pages.offset).limit(@course_pages.per_page) - # - # @course_activity_count=get_course_activity @courses,@course_activity_count - # - # end + courses = Course.visible.where("LOWER(name) like '%#{params[:name].to_s.downcase}%'") + @courses = paginateHelper courses,10 end respond_to do |format| format.html { render :layout => 'course_base' - scope = Course - unless params[:closed] - scope = scope.active - end } format.atom { courses = Course.visible.order('created_on DESC').limit(Setting.feeds_limit.to_i).all diff --git a/app/views/courses/search.html.erb b/app/views/courses/search.html.erb index 98b056487..c19f9821a 100644 --- a/app/views/courses/search.html.erb +++ b/app/views/courses/search.html.erb @@ -39,17 +39,17 @@ <% end %> -<% if @courses.size == 0 %> -<%= render :partial => 'layouts/no_content'%> +<% if @courses && !@courses.empty? %> +