clamp pagination

avoids a sql error when trying to offset a huge number
This commit is contained in:
joshua stein 2016-07-31 12:36:28 -05:00
parent b5f6ab36a8
commit 955c52b5bb
3 changed files with 16 additions and 9 deletions

View file

@ -201,9 +201,11 @@ class CommentsController < ApplicationController
@heading = @title = "Newest Comments"
@cur_url = "/comments"
@page = 1
if params[:page].to_i > 0
@page = params[:page].to_i
@page = params[:page].to_i
if @page == 0
@page = 1
elsif @page < 0 || @page > (2 ** 32)
raise ActionController::RoutingError.new("page out of bounds")
end
@comments = Comment.where(

View file

@ -224,7 +224,13 @@ private
end
def page
params[:page].to_i > 0 ? params[:page].to_i : 1
p = params[:page].to_i
if p == 0
p = 1
elsif p < 0 || p > (2 ** 32)
raise ActionController::RoutingError.new("page out of bounds")
end
p
end
def paginate(scope)

View file

@ -2,13 +2,12 @@ class ModerationsController < ApplicationController
def index
@title = t('.moderationlogtitle')
@page = params[:page] ? params[:page].to_i : 0
@pages = (Moderation.count / 50).ceil
if @page < 1
@page = params[:page].to_i
if @page == 0
@page = 1
elsif @page > @pages
@page = @pages
elsif @page < 0 || @page > (2 ** 32) || @page > @pages
raise ActionController::RoutingError.new("page out of bounds")
end
@moderations = Moderation.order("id desc").limit(50).offset((@page - 1) *