#56 ✓resolved
Matt Aimonetti

will_paginate multiple collections

Reported by Matt Aimonetti | July 16th, 2007 @ 01:44 AM

I recently faced an interesting problem. I wanted to use pagination on 2 different list items in the same page.

Right now, changing the page for 1 list would affect the second list of items (which I don't want).

I quickly hacked a patch to get many paginations working on the same page. I can certainly be refactored but anyway here is how one could use the new param passed to the will_paginate helper.

 <%= will_paginate @stories %>
<%= will_paginate @old_open_stories, {:page_param => 'old_stories_page'} %>

in the controller, one could access the :page param or the old_stories_page parameter.

Matt

Comments and changes to this ticket

  • Matt Aimonetti

    Matt Aimonetti July 16th, 2007 @ 01:44 AM

    • Title changed from “[enhancement][patch] will_paginate paginate multiple list in same page” to “[enhancement][patch] will_paginate paginate multiple lists in the same page”
  • Mislav

    Mislav July 16th, 2007 @ 01:44 AM

    • Title changed from “[enhancement][patch] will_paginate paginate multiple lists in the same page” to “will_paginate multiple collections”
    • State changed from “new” to “open”

    This has been on my roadmap for quite some time. I will make it happen!

  • Charles Brian Quinn

    Charles Brian Quinn July 16th, 2007 @ 01:44 AM

    Nicely done. I started whipping this up and came here to make sure no one had already done it.

    I noticed the patch misses the next and previous links:

            # next and previous buttons
            links.unshift page_link_or_span(entries.previous_page, 'disabled', options.delete(:prev_label), options[:page_param])
            links.push    page_link_or_span(entries.next_page,     'disabled', options.delete(:next_label), options[:page_param])
    

    also patch didn't apply clean on latest (line break issues maybe)?

    possible refactor could pass on options to the link_helper. Sorry, no tests either, I'm guessing an:

    assert_select to verify the correct custom page_param is in the a href links would work.

    Mislav, let me know if you want help or want to just pass off to me.

  • Charles Brian Quinn

    Charles Brian Quinn July 16th, 2007 @ 01:44 AM

    OK,

    i patched and added tests, too.

    here's the pastie:

    http://pastie.textmate.org/76747

    enjoy!

  • Matt Aimonetti (mattetti)

    Matt Aimonetti (mattetti) July 16th, 2007 @ 01:44 AM

    Mislav, any news about this new feature implementation?

  • Mislav

    Mislav July 16th, 2007 @ 01:44 AM

    Matt,

    I will commit as soon as I find time. I've decided to throw in more magic than simply apply the patch from Quinn (BTW, thanks man!)

  • Chris Wanstrath

    Chris Wanstrath July 16th, 2007 @ 01:44 AM

    • State changed from “open” to “resolved”

    (from [300]) WillPaginate: add :param_name option to enable overriding the page parameter name when calling the will_paginate helper. Of course, this defaults to "page" like before. Also add test_will_paginate_preserves_parameters to prove that #65 is invalid. [Matt Aimonetti, Charles Brian Quinn] [#56 state:resolved]

    http://require.errtheblog.com/pl...

Please Sign in or create a free account to add a new ticket.

With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.

New-ticket Create new ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile ยป

Everyone's favorite Ruby library for pagination of practically anything!

Attachments

Pages