1
0
Fork 0
mirror of https://github.com/kaminari/kaminari.git synced 2022-11-09 13:44:37 -05:00

Error happen under model.page(params[:page]).per(params[:per])

This commit is contained in:
ITO Koichi 2011-02-15 18:41:49 +09:00
parent 8a3803697f
commit 4b3a0993da
2 changed files with 12 additions and 3 deletions

View file

@ -16,12 +16,12 @@ module Kaminari
kls.class_eval do
# page(5)
scope :page, lambda {|num|
per_page = @_default_per_page || Kaminari::ActiveRecord::DEFAULT_PER_PAGE
limit(per_page).offset(per_page * ([num.to_i, 1].max - 1))
limit(default_per_page).offset(default_per_page * ([num.to_i, 1].max - 1))
} do
# page(3).per(10)
def per(num)
limit(num).offset(offset_value / limit_value * num)
num = default_per_page if num.to_i == 0
limit(num.to_i).offset(offset_value / limit_value * num.to_i)
end
def num_pages
@ -40,6 +40,10 @@ module Kaminari
def self.paginates_per(val)
@_default_per_page = val
end
def self.default_per_page
@_default_per_page || Kaminari::ActiveRecord::DEFAULT_PER_PAGE
end
end
end
end

View file

@ -66,6 +66,11 @@ describe Kaminari::ActiveRecord do
subject { User.page(50).per(65536) }
its(:num_pages) { should == 1 }
end
context 'per 0 (using default)' do
subject { User.page(50).per(0) }
its(:num_pages) { should == 4 }
end
end
describe '#current_page' do