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?
--
Posted via http://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---