# Array vs Paginate::Collection - weirdness!

**URL:** <https://www.ruby-forum.com/t/array-vs-paginate-collection-weirdness/121763>\
**Category:** Rails\
**Created:** [November 30, 2007, 5:09pm UTC](https://www.ruby-forum.com/t/array-vs-paginate-collection-weirdness/121763 "2007-11-30T17:09:54Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![cmaxvv](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/85f322/32.png) [@cmaxvv](https://www.ruby-forum.com/u/cmaxvv)\
**Post date:** [November 30, 2007, 5:09pm UTC](https://www.ruby-forum.com/t/array-vs-paginate-collection-weirdness/121763/1 "2007-11-30T17:09:54Z")

</div>

I’m using the will\_paginate plugin as well as has\_many\_polymorphs. I  
use the following code to get a list of all of my “Item” objects which  
have a specific tag:

tagged = Tag.find\_by\_name(@search\_term).items

I can then call paginate on it to make a paginator out of the collection  
in tagged:

@results = tagged.paginate(:page =\> 1)

So far so good. The weirdness comes in when i try to do something with  
tagged before passing it to paginator, eg to delete any items with a  
given value

tagged = Tag.find\_by\_name(@search\_term).items.delete\_if{ |x| x.name ==  
“foo” }

Now, the .paginate call won’t work on tagged because it won’t work on an  
array - it seems as if calling an array method on tagged converts it to  
an array.

To make matters more confusing, rails _thinks_ tagged is an array  
already:

tagged = Tag.find\_by\_name(@search\_term).items  
tagged.class  
=\> Array  
@results = tagged.paginate(:page =\> 1) #Works

tagged = Tag.find\_by\_name(@search\_term).items.delete\_if{ |x| x.name ==  
“foo” }  
tagged.class  
=\> Array  
@results = tagged.paginate(:page =\> 1) #Doesn’t work on objects of class  
Array!

Can anyone explain this weirdness?
