On Sun, Aug 16, 2009 at 01:59, wildchild <alexander.uva
...@gmail.com> wrote:
> Just an idea. Consider we have page_size = 20 and just 23 records in
> the storage. Why not display all 23 records without annoying "next
> page" link? Awesome?
Awesome? It frikkin' rules!
But seriously—I've given this a thought when I was experiencing
disappointment if the last page had only a few records. But, having a
constant per_page value was good for consistency, so I never really dared to
cheat on my users this way.
It's easy to implement this if anyone wants to try it:
class Post < ActiveRecord::Base
def self.paginate(options)
result = super
if result.total_pages > 1 and (result.total_entries - result.size)
<= result.per_page/4
result += super(options.merge(:page => result.next_page))
result.paginate(:page => 1, :per_page => result.size)
else
result
end
end
end