Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

helper issue when request.method != :get

#119

So here is my problem, I'm using will_paginate to paginate a list a pictures. The pagination helper is located at the bottom of the panel with all my pictures.

In the in the same page I have an ajax picture editor.

When a picture is edited (update call), the panel with all the questions is reloaded(rjs).

The issue is that I call the helper every time the photo panel is reloaded. Since the helper uses the action params to create the link, my pagination links are all messed up.

I believe that the links should only merge the GET parameters and not the POST and especially not the UPDATE and DELETE params.

What do you think?

-Matt

Reported by Matt Aimonetti (mattetti) · September 26th, 2007 @ 10:10 PM

State: open
Milestone: none
Assigned to: Mislav Mislav

Activity

  1. Matt Aimonetti (mattetti)
    Matt Aimonetti (mattetti)

    on suggestion to fix this problem is to add a new pagination option: pagination_action or default_action.

    in the page_link_or_span method we can easily check on request.method, if we don't get a :get request and we have a pagination_action defined, we can merge the params with the pagination_action and the page info to create a proper link.

    September 26th, 2007 @ 10:18 PM

  2. Matt Aimonetti (mattetti)
  3. Mislav
    Mislav
    • State changed from new to open

    Not so simple. The helper must merge GET or POST params because the page being rendered might be a search initiated by GET or POST and I have to preserve params of the search between pages.

    Can you explain better what you're doing? I didn't understand nothing about updates, panels, questions or ajax reloading. Thanks

    September 26th, 2007 @ 10:38 PM

  4. Matt Aimonetti (mattetti)
    Matt Aimonetti (mattetti)

    I have some update and delete action called remotely which re render a div including some photos and the pagination helper.

    The pagination helper is included in the div because it needs to be refreshed in case some photos were removed.

    The ajax calls are using the UPDATE or DELETE methods to update or delete one or many pictures. The actions called by these remote forms have nothing to do with the action handling the pagination, however since you are merging the request params, the pagination tries to call the same action again.

    I can't find a case where it would make sense for the pagination helper to make an update/delete call to any action.

    Does it make more sense?

    -Matt

    September 26th, 2007 @ 10:57 PM

  5. Fjan
    Fjan

    Same problem here: If you have a nice RESTful controller that renders a list right after a new item was POSTed, the will_paginate plugin will add all the POST info all the links. The classic paginator didn't do that, I wonder how they figured out which params to include. Anyway, I solved it by modifying will_paginate so I could pass in the url options, but that's not nearly as elegant as the classic plugin did it.

    October 5th, 2007 @ 05:45 PM

  6. Mislav
    Mislav

    Fjan, I don't think I'll be supporting that practice, but will definitely make this configurable. You will be able to mess with merged parameters as much as you want

    October 5th, 2007 @ 06:09 PM

  7. Mislav
    Mislav
    • State changed from open to resolved

    Hey Matt, Fjan,

    In changeset [422] I've stopped preserving parameters in pagination links for non-GET requests. So, obviously I listened to Matt's suggestion.

    You can tamper with parameters, though:

    will_paginate @posts, :params => { :foo => 'bar' }
    

    In this example, all page links will have the "foo" parameter. Similarly, with nil values you can prevent certain keys from showing up in page links.

    December 25th, 2007 @ 01:36 AM

  8. Dan
    Dan

    so does that mean that the only way to generate links for the results of a post based search is to manually tell the will_paginate helper the url parameters for the generated links?

    i.e will_paginate @collection, :params => {:controller => 'foo', :action => 'bar'}

    February 19th, 2008 @ 11:48 PM

  9. Mislav
    Mislav

    Dan: yes, and you shouldn't have POST searches anyway.

    February 23rd, 2008 @ 01:41 PM

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.