Rails "Load more..." instead of pagination
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 th开发者_JAVA百科is 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.
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.
精彩评论