课程搜索结果不正确
This commit is contained in:
parent
16aea5ef42
commit
6051d0797d
|
@ -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
|
||||
|
|
|
@ -39,17 +39,17 @@
|
|||
<% end %>
|
||||
</div>
|
||||
|
||||
<% if @courses.size == 0 %>
|
||||
<%= render :partial => 'layouts/no_content'%>
|
||||
<% if @courses && !@courses.empty? %>
|
||||
<div id="courses-index">
|
||||
<%= render_course_hierarchy(@courses)%>
|
||||
</div>
|
||||
<% else %>
|
||||
<div id="courses-index">
|
||||
<%= render_course_hierarchy(@courses)%>
|
||||
</div>
|
||||
<%= render :partial => 'layouts/no_content'%>
|
||||
<% end %>
|
||||
|
||||
<div class="pagination">
|
||||
<ul>
|
||||
<%= pagination_links_full @course_pages %>
|
||||
<%= pagination_links_full @obj_pages, @obj_count, :per_page_links => false %>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
|
|
Loading…
Reference in New Issue