views:

360

answers:

2

Say if I have a set of objects contained in @set. Each of these objects has a description method which will return some text that I want to display on individual pages. How do I use will_paginate to paginate this?

The examples I've seen so far such as:

@articles = Article.paginate :page => params[:page]

look like they are referring to all Article objects.

A: 

To do do the call in active record you just use .paginate instead of .find and pass the necessary arguments, the gem is pretty well documented on how to use it. Installation docs, and usage examples are in the Readme. The examples might not be using your @set but you use it the same way.

Edit: Apparently those links were wrong, The github repo for will_paginate has that wiki and readme file. Do a search on github for it as I seem to be having epic link fail at the moment.

railsninja
Dead links, man.
alamodey
+1  A: 

Assuming your model is called SomeObject, the will_paginate syntax is similar to that of .find():

@set = SomeObject.paginate(:page => params[:page],
                           :per_page => 20
                           :order => 'created_at DESC',
                           :conditions => { :foo => 'bar' })

Check the documentation for more.

Ron DeVera