Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Inconsistent page counting on empty collection #989

@Morred

Description

@Morred

Hi there,
thanks for writing and maintaining this gem <3

We're using it for ActiveRecord pagination in several of our (non-Rails) Ruby apps, and I've recently come across the following behavior that seems somewhat inconsistent.

When called on an empty collection, #current_page returns 1, but #total_pages returns 0:

[1] pry(main)> collection = Item.where(author: author).page(1).per(10)
[]
[2] pry(main)> collection.current_page
1
[3] pry(main)> collection.total_pages
0

If the number of total pages is 0, I'd expect the current page to also be 0, otherwise it would come out looking like Page 1/0 to the user.

Is there a specific reason why current_page returns 1 in this case? If this looks like a bug to you, I'd be happy to look into it.

Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions