I'm trying to use will paginate with ajax, but I don't show the will_paginate
buttons... instead I use a see more
button, that makes an Ajax request and append the results to the page.
what I'm trying to do is disable this see more
button if I hit the last page of records!!
Any idea how to know that the current page is the last page??
Asked
Active
Viewed 8,694 times
14

zeacuss
- 2,563
- 2
- 28
- 32
3 Answers
36
@collection.total_pages == @collection.current_page

adiga
- 34,372
- 9
- 61
- 83

Alexandr Yakubenko
- 564
- 4
- 6
-
3Is there a better API doc for will_paginate that can be used to find these methods? The one on Github falls kind of short. – Steve Nov 13 '14 at 03:18
-
You can also use `@collection.next_page` (or `@collection.next_page.present?`), which reads a bit nicer in my opinion. – fabi Jan 09 '19 at 08:59
-
For a list of collection methods, see: https://www.rubydoc.info/gems/will_paginate/3.1.6/WillPaginate/CollectionMethods – Brian Sep 05 '19 at 18:54
2
Accessing the @collection.total_pages
method will give you the total number of pages currently being returned. You can use this to evaluate against your active page using the @collection.current_page
method. This is still applicable if you're reloading your collection on each expansion.
The implementation will be to use the AJAX call to replace the HTML content if this evaluation is true.

nickpellant
- 1,046
- 1
- 7
- 9
1
You can use next_page
condition
@collection.next_page.present?

adiga
- 34,372
- 9
- 61
- 83

Marcelo Austria
- 861
- 8
- 16