Paginating Partial?

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

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.

[email protected] 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?

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 [email protected]