I have a number of objects I would like to paginate using Kaminari. However, on the first page I would also like to show a notification allowing the viewer to create his own object, reducing the number of objects that can be displayed on that page. However, the indicated number of pages should also take into account that this first page contains less elements.
Let's say the objects are the letters a through z. The first page should only 4 display letters: {a,b,c,d}
, while all other pages should show 6 letters: {e,f,g,h,i,j}, {k,l,m,n,o,p}, etc...
I've been looking at the padding
and offset
functions, but I have not yet been able to produce the wanted results with these.
@page
is the current page
if @page == 1
Alphabet.page(@page).per(4)
else
Alphabet.page(@page).per(6).padding(2)
end
=> {a,b,c,d},{i,j,k,l,m,n}, etc...
if @page == 1
Alphabet.page(@page).per(4)
else
Alphabet.page(@page).per(6).offset(4)
end
=> {a,b,c,d},{e,f,g,h,i,j}, {e,f,g,h,i,j} etc...
The offset method also does not set the current_page correctly, so this does not seem like the correct method.
How can I get pagination that looks like {a,b,c,d}, {e,f,g,h,i,j}, {k,l,m,n,o,p}, etc...
, while also displaying the correct number of pages on the first page, in this case 5?