I really enjoy using will_paginate, it's very well written and the authors keep up with the bugs and new features.
Start by installing will_paginate:
Then go watch the Railcast screencast about will paginate.
Once you have your pagination working, we will do some ' progressive enhancement'.
To do that, you simply need to add the excellent 'lowpro' Prototype extension from Dan Webb
You can get the files directly from the lowpro's repository.
Create a behavior
Event.addBehavior.reassignAfterAjax = true;Refresh your cache, reload your page, and test the link. It will probably look like it doesn't do anything but if you are using firebug or if you are checking your logs, you'll notice something happened. The problem is that we didn't tell our action to send an Ajax response so we get the html full page all over again.
'div.pagination a' : Remote.Link
def indexPerfect! Now when a visitor clicks on my pagination links, only the photos are paginated, the rest of the page stays the same. Note that my navigation bar is inside the partial so it gets 'updated' after a visitor clicks on any pagination link.
@photos = Photo.paginate(:all, :conditions => ["photos.user_id = ?", current_user.id], :page => params[:page])
respond_to do |format|
format.html # index.html.erb
render :update do |page|
page.replace_html 'photos', :partial => "photos"