Module: Kaminari::PageScopeMethods::InstanceMethods

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

Instance Method Summary collapse

Instance Method Details

#current_pageObject

Current page number



21
22
23
# File 'lib/kaminari/models/page_scope_methods.rb', line 21

def current_page
  (offset_value / limit_value) + 1
end

#first_page?Boolean

First page of the collection ?

Returns:

  • (Boolean)


26
27
28
# File 'lib/kaminari/models/page_scope_methods.rb', line 26

def first_page?
  current_page == 1
end

#last_page?Boolean

Last page of the collection?

Returns:

  • (Boolean)


31
32
33
# File 'lib/kaminari/models/page_scope_methods.rb', line 31

def last_page?
  current_page >= num_pages
end

#num_pagesObject

Total number of pages



16
17
18
# File 'lib/kaminari/models/page_scope_methods.rb', line 16

def num_pages
  (total_count.to_f / limit_value).ceil
end

#per(num) ⇒ Object

Specify the per_page value for the preceding page scope

Model.page(3).per(10)


7
8
9
10
11
12
13
# File 'lib/kaminari/models/page_scope_methods.rb', line 7

def per(num)
  if (n = num.to_i) <= 0
    self
  else
    limit(n).offset(offset_value / limit_value * n)
  end
end