# Will\_paginate not from model, in array?

**URL:** <https://www.ruby-forum.com/t/will-paginate-not-from-model-in-array/122580>\
**Category:** Rails\
**Created:** [December 9, 2007, 8:39pm UTC](https://www.ruby-forum.com/t/will-paginate-not-from-model-in-array/122580 "2007-12-09T20:39:06Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![miked](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/ed655f/32.png) [@miked](https://www.ruby-forum.com/u/miked)\
**Post date:** [December 9, 2007, 8:39pm UTC](https://www.ruby-forum.com/t/will-paginate-not-from-model-in-array/122580/1 "2007-12-09T20:39:06Z")

</div>

Hi:

I’ve got an array i’d like to paginate. It’s a collection of the same  
model, but I can’t seem to paginate accordingly. Here’s my code:

\<%pics = PictureCategory.find\_goal\_pics(uid)  
pics = pics.paginate  
pics.each do |p| %\>

  
\<%= image\_tag(p.public\_filename(:small), :alt =\> “goal  
picture”, :class =\> “goalpic”)%\>  
  
\<%= p.picture\_category.name %\>  

  
\<% end %\>  
\<% end %\>  
  
\<%= will\_paginate pics %\>

But there’s no pagination on the page, similarly I tried:

pics = pics.paginate(:all, :per\_page =\> 8)

which didn’t work either. I’m sure I don’t understand enough about  
will\_paginate. You help is as always greatly appreciated.

Mike

---

<div class="post-metadata">

**Author:** ![miked](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/ed655f/32.png) [@miked](https://www.ruby-forum.com/u/miked)\
**Post date:** [December 10, 2007, 6:54am UTC](https://www.ruby-forum.com/t/will-paginate-not-from-model-in-array/122580/2 "2007-12-10T06:54:23Z")

</div>

This is the we got the output:

@docket\_types = DocketType.paginate :page =\> params[:page], :per\_page  
=\> 5, :conditions =\> [“court\_id in (#{@current\_user.court\_ids.join(’,  
')})”]

\<%= will\_paginate @docket\_types %\>

---

<div class="post-metadata">

**Author:** ![miked](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/ed655f/32.png) [@miked](https://www.ruby-forum.com/u/miked)\
**Post date:** [December 24, 2007, 8:15pm UTC](https://www.ruby-forum.com/t/will-paginate-not-from-model-in-array/122580/3 "2007-12-24T20:15:08Z")

</div>

So I’m still having problmes, having just discovered that even though  
pagination correctly splits up my page, when you click on a page link,  
it doesn’t actually work! ☹

My problem is that the array I compile is actually a combination of a  
few different type of models. What do I do in this case (notice the  
hack at the end):

def index  
@goals = Search.search\_goals(params[:search])  
@people = Search.search\_people(params[:search])  
@all = []  
#mark goals and people and teams for easier presentation processing  
(has to do with the way I display in the view)  
@goals.each do |g|  
@all \<\< [“g”,g]  
end  
@people.each do |p|  
@all \<\< [“p”,p]  
end  
#here’s the pagination hack  
all\_temp = @all  
@all = all\_temp.paginate

end

note that:

@all = all\_temp.paginate(:all, :page =\> params[:page], :per\_page =\> 10)  
gives the error:

undefined method `to\_i’ for {:per\_page=\>10}:Hash

Any help you can give would be greatly appreciated!
