alamodey
alamodey

Reputation: 14953

How do you use will_paginate?

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.

Upvotes: 2

Views: 5592

Answers (2)

Ron DeVera
Ron DeVera

Reputation: 14644

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

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

Check the documentation for more.

Upvotes: 4

nitecoder
nitecoder

Reputation: 5486

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.

Upvotes: 0

Related Questions