Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to insert a page break manually in Rails?

In my project, an Article has many Items within it. Since each Item has different length, so I would like to implement pagination manually, for example, by creating a PageBreakItem model, in order to allow users insert page breaks wherever they want. But I don't know how to use "page" parameter in controller to render views correctly.

Some gems like kaminari or will_paginate only allow me to configure the number of items per page. They don't have options for inserting page breaks manually.

Any suggestions are greatly appreciated.

like image 201
Van Huy Avatar asked Dec 27 '25 19:12

Van Huy


1 Answers

You don't need a special model for this. You could do this with small adaptation of your Item model: Add sort_order numeric field to denote order of items within the article and is_on_new_page boolean field to denote a page break occurring before that article.

like image 62
AmitA Avatar answered Dec 30 '25 11:12

AmitA