views:

137

answers:

2

I have a list of elements, and I've been using will_paginate up until now, but I'd like to have something like "load more..." at the bottom of the list. Is there an easy way to accomplish this using will_paginate or do I need to resort to some other method here?

From what I know this is a better route anyhow because then I don't need a SQL count of the records. And it really doesn't matter if there are like 9,847 pages, nobody would need the records beyond the first couple pages anyhow.

+3  A: 

Watch this screencast called endless page for details about implementing a solution for your problem.

KandadaBoggu
+2  A: 

Take a look how Twitter or Brightkite implement their "Load More" buttons (for the javascript side of things). You'll still want to have some sort of pagination mechanism in your rails app. It probably doesn't need to be as complex as will_paginate. Maybe something like this in your controller:

# where 10 is the number of records per page
Record.find(:all, :conditions => {:offset => params[:page] * 10, :limit => 10})

Then in your AJAX call to get more records you'll need to pass back the proper "page" number and be sure to increment it every time the load more button is pressed.

vrish88
Wow, this is really awesome. How simple and lightweight.
Joseph Silvashy