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?