Rails 3 Kaminari fallback to first page if current page is out_of_range - ruby-on-rails-3

I want to fallback to page 1 if the page number provided is out_of_range?.
For example if there are total 10 records and per_page is 5 which makes two pages. I want to fall back to page 1 if someone tries to hit page 3 which doesn't exist.
We are using kaminari (0.16.1).

Related

BigCommerce Stencil CLI Blog - Conditions

Is there any possible way to display blogs in BC from a certain count? For example, I want my top 3 most recent posts on the top of the blog page, but then beneath in a different format 4 onward would display. Anyway to start with the 4th blog down?
They are returned in most recent order, but you can limit the total to 7 in your example. I would then use Handlebar helpers in your Stencil theme to grab the first 3 for the top section and the next for for the last section. {{#for 1 3}}{{/for}} for the top section and {{#for 4 8}}{{/for}} for the bottom section

Why cursor-based pagination in shopify ignores last page?

I'm using shopify api to get list of orders
For first request I use this URL:
https://my-shop-name.myshopify.com/admin/orders.json?status=any&order=created_at+desc&limit=250
and for all next use link to next page from response headers like described here:
Pagination with a link header
The problem is that last page or orders always gets ignored, because request for previous page doesn't contain link to next one.
That's weird, because it takes all orders from 4403 to 1153 (with 250 limit it's 13 pages) and it should make one more request (latest order number is 1101), to get latest 52 orders. Maybe the problem is in 250 limit parameter, but I don't know how to bypass it if I don't know exact number of orders

How to fetch specific amount of users using github api v3?

When I want to fetch github users using this api: https://api.github.com/users it gives me back exactly 46 users. How can I fetch e.g. just 10 of them?
You can try and add the per_page directive in your API URL
By passing the per_page parameter, you can specify how many items you want each page to return, up to 100 items.
Let's try asking for 10 items about addClass:
curl -I "https://api.github.com/search/code?q=addClass+user:mozilla&per_page=10"
Apply the same idea to api.github.com/users
The first "page" of result would be 10 users.

Token to the next page in pagination API

I have a list of records on the server sorted by a key and use pagination API to return list of segments one by one. Since items can be inserted in the middle of the list, I return the first key of the next page as a pagination token that has to be passed to get the next page.
However, I've found that DynamoDB uses the last key of the current page instead for querying API, which is null if the next page does not exist.
Question:
What are pros and cons between using the last item of the current page and the first item of the next page as a pagination token?
N.B:
As for me returning the first item is more intuitive since it's null only if the next page does not exist.
Using the "last item of the current page" (LICP) is better than using the "first item of the next page" (FINP) because it deals better with the possibility that, in the meantime, some item is inserted between these two items.
For example suppose the first page contains 3 alphabetically ordered names: Adam/Basil/Claude. And suppose the next page is Elon/Francis/Gilbert.
Then with LICP the token is Claude, while with FINP the token is Elon. If no new names are inserted, the result is the same when we get the next page.
However, suppose we insert the name Daniel after getting the first page but before getting the second page. In this case, when we get the second page with LICP we get Daniel/Elon/Francis, while with FINP we get Elon/Francis/Gilbert. That is to say, FINP will miss Daniel, while LICP will not.
Also, FINP may consume more computing resources than LICP, since you must retrieve one extra item (4 items, in the above example, instead of only 3).

Angellist api: How to get to second page of data?

I was looking at Angel list api (https://angel.co/api) and I noticed a section on pagination. It says entries are limited to max of 50 (for eg. https://api.angel.co/1/users/135/roles has 2 pages work of data but returns only 1 page). The documentation mentions pagination but does not say how to get 2nd page.
Any ideas?
Chetan
Add ?page=2 to the end of the request to get the second page.