-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix bug last_page? wrong when current_page is 1 and total_pages is 0 (version 1.0.1) #877
Conversation
Could you elaborate? Theoretically |
@yuki24 , Thank you very much for your replied
There are 2 scenario below: How do you think about those two cases? |
This is my case. #controller
@entries = Entry.where()... #=> Entry.none #view
json = {}
json[:_links] = {}
json[:_links][:self] = { href: entries_url(page: @entries.current_page, limit: @entries.limit_value) }
json[:_links][:prev] = { href: entries_url(page: @entries.prev_page, limit: @entries.limit_value) } unless @entries.first_page?
json[:_links][:next] = { href: entries_url(page: @entries.next_page, limit: @entries.limit_value) } unless @entries.last_page? I should use
|
@sanemat In your case, I think we only need
because @entries.next_page will return |
It seems that you could just the if !users.last_page? || !users.out_of_range?
result[:page] += 1
result[:display_next_button] = true
end Please also have a look at the paginator template for how you could show/hide pagination links. I would also recommend implementing RFC5988 rather than passing flags and page numbers around. I'm not sure about your codebase but I have a hunch that there's a better way of showing a link to the next page. |
@@ -337,7 +337,7 @@ def shutdown | |||
end | |||
|
|||
test 'out of range' do | |||
assert_false model_class.page(11).per(10).last_page? | |||
assert_true model_class.page(11).per(10).last_page? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we should change this since this is mathematically incorrect.
@yuki24 Thank you for corrected me. |
I'm closing this issue since kaminari used to behave exactly like the proposed behavior before. Thanks! |
Apparently this is the intended behavior, see #583. |
thank you for the information (y) |
I found a bug when when
current_page is 1
andtotal_pages is 0
(There last page is also last page in this case)When I tried to query like this: User.where(id: 'not_exist').page(1).per(10)
Then last_page? is
false
But it's should betrue
.Please review and comfirm if I am correct. thanks