KathysKode-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2008-Aug-22 13:15 UTC
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 --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
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. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
KathysKode-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org 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. > KathleenI 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? -- 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 -~----------~----~----~----~------~----~------~--~---
KathysKode-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2008-Aug-23 12:51 UTC
Re: Paginating Partial?
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? %> <fieldset style="float:left; width:98%; margin:2px; padding-top: 3px;"> <legend style="color:#ffffff;">Transactions</legend> <% @atxes = @asset.atxes.paginate :per_page => 5, :page => params[:page] %> <%= render :partial => ''asset/atxes/body'' %> <%= will_paginate @atxes %> </fieldset> <% end %> Kathleen On Aug 22, 10:25 am, Ar Chron <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> KathysK...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org 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? > > -- > Posted viahttp://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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---