Method: Kaminari::PageScopeMethods#per

Defined in:
lib/kaminari/models/page_scope_methods.rb

#per(num, max_per_page: nil) ⇒ Object

Specify the per_page value for the preceding page scope

Model.page(3).per(10)


7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/kaminari/models/page_scope_methods.rb', line 7

def per(num, max_per_page: nil)
  max_per_page ||= ((defined?(@_max_per_page) && @_max_per_page) || self.max_per_page)
  @_per = (num || default_per_page).to_i
  if (n = num.to_i) < 0 || !(/^\d/ =~ num.to_s)
    self
  elsif n.zero?
    limit(n)
  elsif max_per_page && (max_per_page < n)
    limit(max_per_page).offset(offset_value / limit_value * max_per_page)
  else
    limit(n).offset(offset_value / limit_value * n)
  end
end