# Paginating a find

**URL:** <https://www.ruby-forum.com/t/paginating-a-find/109206>\
**Category:** Rails\
**Created:** [July 12, 2007, 12:28pm UTC](https://www.ruby-forum.com/t/paginating-a-find/109206 "2007-07-12T12:28:21Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![nanouk](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/da6949/32.png) [@nanouk](https://www.ruby-forum.com/u/nanouk)\
**Post date:** [July 12, 2007, 12:28pm UTC](https://www.ruby-forum.com/t/paginating-a-find/109206/1 "2007-07-12T12:28:21Z")

</div>

def summary  
@most\_recent\_fails = Run.find(:all, :order =\> ‘id DESC’)  
@fails\_pages, @most\_recent\_fails = paginate :most\_recent\_fails,  
:per\_page =\> 2, :conditions =\> [‘run\_id=?’, @run.id]  
end

Brings up the following error:

Called id for nil, which would mistakenly be 4 – if you really wanted  
the id of nil, use object\_id

Any ideas why?

---

<div class="post-metadata">

**Author:** ![nanouk](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/da6949/32.png) [@nanouk](https://www.ruby-forum.com/u/nanouk)\
**Post date:** [July 12, 2007, 12:33pm UTC](https://www.ruby-forum.com/t/paginating-a-find/109206/2 "2007-07-12T12:33:03Z")

</div>

Paul N. wrote:

> def summary  
> @most\_recent\_fails = Run.find(:all, :order =\> ‘id DESC’)  
> @fails\_pages, @most\_recent\_fails = paginate :most\_recent\_fails,  
> :per\_page =\> 2, :conditions =\> [‘run\_id=?’, @run.id]  
> end
> 
> Brings up the following error:
> 
> Called id for nil, which would mistakenly be 4 – if you really wanted  
> the id of nil, use object\_id
> 
> Any ideas why?

How and where do you set up @run (for use in @run.id)?

Roberto Gattinoni.

---

<div class="post-metadata">

**Author:** ![nanouk](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/da6949/32.png) [@nanouk](https://www.ruby-forum.com/u/nanouk)\
**Post date:** [July 12, 2007, 12:34pm UTC](https://www.ruby-forum.com/t/paginating-a-find/109206/3 "2007-07-12T12:34:14Z")

</div>

Roberto Gattinoni wrote:

> Paul N. wrote:
> 
> > def summary  
> > @most\_recent\_fails = Run.find(:all, :order =\> ‘id DESC’)  
> > @fails\_pages, @most\_recent\_fails = paginate :most\_recent\_fails,  
> > :per\_page =\> 2, :conditions =\> [‘run\_id=?’, @run.id]  
> > end
> > 
> > Brings up the following error:
> > 
> > Called id for nil, which would mistakenly be 4 – if you really wanted  
> > the id of nil, use object\_id
> > 
> > Any ideas why?
> 
> How and where do you set up @run (for use in @run.id)?
> 
> Roberto Gattinoni.

Ahh, i haven’t.

I guess it should be changed to @most\_recent\_fails?

---

<div class="post-metadata">

**Author:** ![nanouk](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/da6949/32.png) [@nanouk](https://www.ruby-forum.com/u/nanouk)\
**Post date:** [July 12, 2007, 12:36pm UTC](https://www.ruby-forum.com/t/paginating-a-find/109206/4 "2007-07-12T12:36:54Z")

</div>

Paul N. wrote:

> def summary  
> @most\_recent\_fails = Run.find(:all, :order =\> ‘id DESC’)  
> @fails\_pages, @most\_recent\_fails = paginate :most\_recent\_fails,  
> :per\_page =\> 2, :conditions =\> [‘run\_id=?’, @run.id]  
> end

Notice there’s a will\_paginate plugin which seems to be the preferred  
way to do pagination these days.

–  
Cheers,

- Jacob A.

---

<div class="post-metadata">

**Author:** ![nanouk](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/da6949/32.png) [@nanouk](https://www.ruby-forum.com/u/nanouk)\
**Post date:** [July 12, 2007, 2:37pm UTC](https://www.ruby-forum.com/t/paginating-a-find/109206/5 "2007-07-12T14:37:06Z")

</div>

Paul N. wrote:

> Roberto Gattinoni wrote:
> 
> > Paul N. wrote:
> > 
> > > def summary  
> > > @most\_recent\_fails = Run.find(:all, :order =\> ‘id DESC’)  
> > > @fails\_pages, @most\_recent\_fails = paginate :most\_recent\_fails,  
> > > :per\_page =\> 2, :conditions =\> [‘run\_id=?’, @run.id]  
> > > end
> > > 
> > > Brings up the following error:
> > > 
> > > Called id for nil, which would mistakenly be 4 – if you really wanted  
> > > the id of nil, use object\_id
> > > 
> > > Any ideas why?
> > 
> > How and where do you set up @run (for use in @run.id)?
> > 
> > Roberto Gattinoni.
> 
> Ahh, i haven’t.
> 
> I guess it should be changed to @most\_recent\_fails?

@most\_recent\_fails is a collection (result of your Run.find)

Why do you put a condition in the paginate plugin and not in the  
Run.find? After all if I understand correctly you are trying to filter  
the Run model, so why don’t you do that before paginating? You should  
explain where does @run.id come from (a previous form, a user selection,  
…).

Roberto Gattinoni.

---

<div class="post-metadata">

**Author:** ![nanouk](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/da6949/32.png) [@nanouk](https://www.ruby-forum.com/u/nanouk)\
**Post date:** [July 14, 2007, 9:08pm UTC](https://www.ruby-forum.com/t/paginating-a-find/109206/6 "2007-07-14T21:08:24Z")

</div>

Paul N. wrote:

> :per\_page =\> 2, :conditions =\> [‘run\_id=?’, @run.id]

> Called id for nil, which would mistakenly be 4 – if you really wanted  
> the id of nil, use object\_id

That’s the standard “whiny” error message you get when you call nil.id.

id is a (deprecated) member of Object, and an important member of any  
ActiveRecord model. So one of your models is nil - probably @run.

Tip: better delimiters and linefeeds would have helped you spot the  
error  
faster:

```
@fails_pages, @most_recent_fails =
    paginate(
        :most_recent_fails,
        :per_page => 2,
        :conditions => ['run_id=?', @run.id])

```

–  
Phlip  
[Test Driven Ajax (on Rails) [Book]](http://www.oreilly.com/catalog/9780596510657/)  
“Test Driven Ajax (on Rails)”  
assert\_xpath, assert\_javascript, & assert\_ajax

---

<div class="post-metadata">

**Author:** ![nanouk](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/da6949/32.png) [@nanouk](https://www.ruby-forum.com/u/nanouk)\
**Post date:** [July 12, 2007, 8:10pm UTC](https://www.ruby-forum.com/t/paginating-a-find/109206/7 "2007-07-12T20:10:01Z")

</div>

refer to the following post for more information about paginating result  
sets:

[http://tinyurl.com/35m7e7](http://tinyurl.com/35m7e7)

Mike
