# Paginating Partial?

**URL:** <https://www.ruby-forum.com/t/paginating-partial/146575>\
**Category:** Rails\
**Created:** [August 22, 2008, 3:16pm UTC](https://www.ruby-forum.com/t/paginating-partial/146575 "2008-08-22T15:16:05Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [August 22, 2008, 3:16pm UTC](https://www.ruby-forum.com/t/paginating-partial/146575/1 "2008-08-22T15:16:05Z")

</div>

I’ve settled on a design where the parent ‘show’ view holds the  
partial(s) that display the children. As an example if the parent  
record is ‘auto’ the child records are ‘fillups’.  
After many years the fuel fillups for one automobile will increase in  
number and when I do a ‘show’ for the automobile record the list of  
‘fillups’ could be a very long page.  
My question:  
Is there a strategy that some of you have used to invoke the behavior  
of will\_paginate upon a child listing that is called by a partial?  
I am grateful for any reply and expect this is a common question for  
mature databases.  
Kathleen

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [August 22, 2008, 4:25pm UTC](https://www.ruby-forum.com/t/paginating-partial/146575/2 "2008-08-22T16:25:56Z")

</div>

I don’t see where exactly the problem is.  
You get the records in paginated form (Store the current page & num  
pages in session or as part of url)  
Then render the page and use will\_paginate or whatever  
in the partial as anywhere else.

working example from a project: (members who have products)

has\_many :products, :dependent =\> :destroy do  
def paginated\_finished(page, per\_page)  
paginate(:all, :conditions =\> {:status =\> 1}, :order =\>  
“created\_at DESC”, :page =\> page, :per\_page =\> per\_page)  
end  
end

usage in controller:  
@products = member.products.paginated\_finished(params[:page],  
params[:per\_page])

In case of partial usage I would definitely use Ajax to  
do the prev/next page handling.

Another minor problem may be, that you have several  
paginated items on the screen & the system would need  
to know, to which one the page & per\_page optins belong.  
Not sure, but I guess will\_paginate would allow to change  
those names, otherwise just create those two links by hand  
and send them to the ajax action.

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [August 22, 2008, 6:25pm UTC](https://www.ruby-forum.com/t/paginating-partial/146575/3 "2008-08-22T18:25:55Z")

</div>

removed\_email\_address@domain.invalid wrote:

> My question:  
> Is there a strategy that some of you have used to invoke the behavior  
> of will\_paginate upon a child listing that is called by a partial?  
> I am grateful for any reply and expect this is a common question for  
> mature databases.  
> Kathleen

I ended up turning a similar problem on its head (as soon as one testing  
scenario had 38 individual unit tests)…

Rather than your autos\_controller’s ‘show’ form rendering a fillups  
partial that you’re trying to paginate, what about the  
fillups\_controller’s ‘index’ form filtered by the appropriate auto (with  
pagination) rendering an auto partial in a header area?

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [August 23, 2008, 2:51pm UTC](https://www.ruby-forum.com/t/paginating-partial/146575/4 "2008-08-23T14:51:50Z")

</div>

If anyone’s seriously interested in achieving this goal, I stumbled  
upon the way to do it last night. Here it is;

\<% if @asset.atxes and not @asset.atxes.empty? %\>

 Transactions \<% @atxes = @asset.atxes.paginate :per\_page =\> 5, :page =\> params[:page] %\> \<%= render :partial =\> 'asset/atxes/body' %\> \<%= will\_paginate @atxes %\> \<% end %\>

Kathleen

On Aug 22, 10:25 am, Ar Chron [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
