I have a large number of products that I want to display in pdf, with category headings. If the category is not suitable for the current page, I want to move it to another. For this, I use the Prawn group method.
Product.all.group_by(&:category).each do |category, products|
pdf.group do
pdf.text category
pdf.table products.map{ |p| [p.title, p.price] }
end
end
This works very well for a small number of products, but when I add more than 100 or so, it takes a very long time and then ends up like this: "memory allocation failed." If I do not use the group method, it takes about 30 seconds.
Obviously, the group method does not use memory very well. Any suggestions on workarounds would be appreciated.