# \[n00b\] Having problems with find() results

**URL:** <https://www.ruby-forum.com/t/n00b-having-problems-with-find-results/115632>\
**Category:** Rails\
**Created:** [September 27, 2007, 1:09am UTC](https://www.ruby-forum.com/t/n00b-having-problems-with-find-results/115632 "2007-09-27T01:09:31Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![olie](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/o/c4cdca/32.png) [@olie](https://www.ruby-forum.com/u/olie)\
**Post date:** [September 27, 2007, 1:09am UTC](https://www.ruby-forum.com/t/n00b-having-problems-with-find-results/115632/1 "2007-09-27T01:09:31Z")

</div>

I’ve just recently started learning rails, and everything is going well  
for my find(:all) situations. I’m now trying to do limited find, vis:

```
def bug_table
    @Bug_list = Bug.find(:all,
        :conditions => [ "bug_status NOT LIKE 'CLOSED' and

```

bug\_status NOT LIKE ‘VERIFIED’" ]  
)

```
    @bug_pages, @bugs = paginate @Bug_list, :per_page => 25,

```

\<-- line 22  
:order\_by =\> ‘priority, bug\_severity, bug\_id’

```
    render :action => 'list'
end

```

and I get

“#Bug:0x25a4be0#Bug:0x25a48d4[a gazillion other bug objects, snip]”  
is not a valid constant name!

The error claims the problem is in  
app/controllers/bugs\_controller.rb:22:in `bug\_table’, which I presume  
means lines 22 & 23 (it’s a continued line) – so it doesn’t seem to  
want to … what? Does paginate require a “constant”? I thought that  
making @Bug\_list start with a capital letter would made it a constant.  
The probem seems to be more along the line that an array (of  
bug-objects) is returned, and I can’t seem to feed those to paginate.

By comparison, this works just fine:

```
def list
    @bug_pages, @bugs = paginate :bugs, :per_page => 25,
        :order_by => 'priority, bug_severity, bug_id'
end

```

Any help or hints about how to do the thing I want in bug\_table?

Thanks!

---

<div class="post-metadata">

**Author:** ![olie](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/o/c4cdca/32.png) [@olie](https://www.ruby-forum.com/u/olie)\
**Post date:** [September 27, 2007, 2:36am UTC](https://www.ruby-forum.com/t/n00b-having-problems-with-find-results/115632/2 "2007-09-27T02:36:59Z")

</div>

paginate just doesn’t take a collection of objects (and there’s no  
reason it should really - you’re half defeating the point of pagination  
if what you’re doing is loading all the objects first and then only  
displaying 25.

paginate takes the options find does (:conditions, :joins, :order,  
:include etc… so why not do

paginate :bugs, :per\_page =\> 25,  
:order\_by =\> ‘priority, bug\_severity, bug\_id’,  
:conditions =\> “bug\_status NOT LIKE ‘CLOSED’ and  
bug\_status NOT LIKE ‘VERIFIED’”

?

Fred

---

<div class="post-metadata">

**Author:** ![olie](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/o/c4cdca/32.png) [@olie](https://www.ruby-forum.com/u/olie)\
**Post date:** [September 27, 2007, 2:48am UTC](https://www.ruby-forum.com/t/n00b-having-problems-with-find-results/115632/3 "2007-09-27T02:48:32Z")

</div>

Frederick C. wrote:

> paginate takes the options find does (:conditions, :joins, :order,  
> :include etc…)

Ah, THAT’S the info I was missing. Works perfectly, thanks!

> paginate just doesn’t take a collection of objects (and there’s no  
> reason it should really - you’re half defeating the point of pagination  
> if what you’re doing is loading all the objects first and then only  
> displaying 25.

But I thought paginate DID take a collection as its first parameter.  
Ok, I promise not to try to abuse it in the future, but why didn’t it  
like my collection? That is: I see the logic-error, but what was the  
SYNTAX error?

Also, in the case where I’ve already gathered together an  
array/collection/hash/whatever of 1000 of something, and I’d now like to  
show them :per\_page at a time, is there a decent way to feed them to  
paginate? Or is this always an indication that I might want to re-think  
my structure, some?

Thanks!

---

<div class="post-metadata">

**Author:** ![olie](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/o/c4cdca/32.png) [@olie](https://www.ruby-forum.com/u/olie)\
**Post date:** [September 27, 2007, 4:06am UTC](https://www.ruby-forum.com/t/n00b-having-problems-with-find-results/115632/4 "2007-09-27T04:06:35Z")

</div>

Olie D. wrote:

> But I thought paginate DID take a collection as its first parameter.  
> Ok, I promise not to try to abuse it in the future, but why didn’t it  
> like my collection? That is: I see the logic-error, but what was the  
> SYNTAX error?

it doesn’t take a collection as its first parameter. It takes a symbol  
and (by default) tries to guess a class name from that symbol (eg :bug  
=\> Bug). That’s blatently not going to work

> Also, in the case where I’ve already gathered together an  
> array/collection/hash/whatever of 1000 of something, and I’d now like to  
> show them :per\_page at a time, is there a decent way to feed them to  
> paginate? Or is this always an indication that I might want to re-think  
> my structure, some?

paginate won’t do that. There are other pagination plugins  
(will\_paginate springs to mind), maybe some of them handle this.

Fred
