搜索分页修改

This commit is contained in:
yuanke 2016-10-13 09:52:05 +08:00
parent 068a66ac35
commit 0265b6bfb7
1 changed files with 8 additions and 8 deletions

View File

@ -190,7 +190,7 @@ class WelcomeController < ApplicationController
case params[:search_type] case params[:search_type]
when 'all' when 'all'
if (page-1)*20 > @total_count if (page-1)*20 >= @total_count
page = 1 page = 1
params[:page] = "1" params[:page] = "1"
end end
@ -220,42 +220,42 @@ class WelcomeController < ApplicationController
} }
},[User,Syllabus,Course,Attachment,Project,Memo] ).page(page).per(20).results },[User,Syllabus,Course,Attachment,Project,Memo] ).page(page).per(20).results
when 'user' when 'user'
if (page-1)*20 > @users_count if (page-1)*20 >= @users_count
page = 1 page = 1
params[:page] = "1" params[:page] = "1"
end end
@users = User.search(@name).page(page).per(20) @users = User.search(@name).page(page).per(20)
when 'syllabus' when 'syllabus'
if (page-1)*20 > @syllabus_count if (page-1)*20 >= @syllabus_count
page = 1 page = 1
params[:page] = "1" params[:page] = "1"
end end
@syllabuses = Syllabus.search(@name).page(page).per(20).results @syllabuses = Syllabus.search(@name).page(page).per(20).results
when 'project' when 'project'
if (page-1)*20 > @project_count if (page-1)*20 >= @project_count
page = 1 page = 1
end end
@projects = Project.search(@name).page(page).per(20).results @projects = Project.search(@name).page(page).per(20).results
when 'course' when 'course'
if (page-1)*20 > @course_count if (page-1)*20 >= @course_count
page = 1 page = 1
params[:page] = "1" params[:page] = "1"
end end
@courses = Course.search(@name).page(page).per(20).results @courses = Course.search(@name).page(page).per(20).results
when 'attachment' when 'attachment'
if (page-1)*20 > @attach_count if (page-1)*20 >= @attach_count
page = 1 page = 1
params[:page] = "1" params[:page] = "1"
end end
@attachments = Attachment.search(@name).page(page).per(20).results @attachments = Attachment.search(@name).page(page).per(20).results
when 'memo' when 'memo'
if (page-1)*20 > @memo_count if (page-1)*20 >= @memo_count
page = 1 page = 1
params[:page] = "1" params[:page] = "1"
end end
@memos = Memo.search(@name).page(page).per(20).results @memos = Memo.search(@name).page(page).per(20).results
else else
if (page-1)*20 > @total_count if (page-1)*20 >= @total_count
page = 1 page = 1
params[:page] = "1" params[:page] = "1"
end end