Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

Will_Paginate #80

Closed
morgz opened this Issue Mar 5, 2012 · 15 comments

Comments

Projects
None yet
9 participants

morgz commented Mar 5, 2012

Out the box I'm struggling to get will_paginate to work with ransack. It filters the first page of results just fine but doesn't remember the query for the subsequent pages.

Am I just expecting too much?

graywh commented Mar 8, 2012

Ernie says it's possible: #78

morgz commented Mar 9, 2012

I ended up switching to kaminari which just worked

On 8 Mar 2012, at 21:46, Will Grayreply@reply.github.com wrote:

Ernie says it's possible: #78


Reply to this email directly or view it on GitHub:
ernie#80 (comment)

graywh commented Mar 15, 2012

Would you elaborate?

morgz commented Mar 15, 2012

Well I tried it with will paginate and it didn't work out the box. Second page lost the search term. I implemented the kaminari paging gem which is very similar and it 'just worked' ;)

Member

radar commented Mar 28, 2012

Hi @morgz! Do you have an application that I could use to reproduce this issue? Thanks!

Fwiw, I'm using will_paginate (3.0.3), rails (3.2.2), and ransack (0.6.0) with the ReadMe's "Simple Mode" (ie: query string params, not post).

In the example below, @people is an ActiveRecord::Relation instance so I expected pagination to work fine and it does, no problems:

@people = @q.result(:distinct => true).paginate(:page => params[:page], :per_page => 40) if params[:q]

This gem is a fantastic time-saver. Thank you Ernie.

Member

radar commented Mar 29, 2012

Closing until there can be proven there's an issue here.

@radar radar closed this Mar 29, 2012

I'm having the same issue. When I switch to page 2 for ex :

Request

Parameters:

{"page"=>"2",
"id"=>"search"}

The request params are lost

Member

jonatack commented Dec 1, 2014

will_paginate has worked fine together with Ransack since the beginning (I use the two together in production since 3 years), so the issue is probably with your code.

If you find a new issue, would you please file a proper issue as per the Contributing Guide? Thanks.

ffscalco commented Dec 4, 2014

Well, Ransack (via get) and will_paginate works fine for me, but if I use ransack (via post) the pagination is lost

Member

jonatack commented Dec 4, 2014 edited

Thanks @ffscalco. Could you please share a failing test and your Ransack/Rails/Ruby versions?

ffscalco commented Dec 5, 2014

Sure @jonatack!
Versions:

  • Ruby: 2.1.2
  • Rails: 4.1.7
  • Will_paginate: 3.0.6
  • Ransack: 1.5.1

But I guess this is some "miss code"
The pagination doesn't work because the links for pages in will_paginate is via GET, of course it wouldn't work if ransack is in POST mode ;]

I don't know the best way to treat this. If is modify the links in will_paginate to post page instead get, or just use some javascripts.

@ffscalco If you go here this person (rvsingh) has resolved the issue:

http://railscasts.com/episodes/370-ransack?view=comments

Per his comments, make this change in routes. And it works.

resources :styles do
  collection do
    match 'search' => 'styles#index', :via => [:get, :post], :as => :search
  end
end
Member

jonatack commented Apr 9, 2015

FWIW the README also suggests something similar for the routes.

To the contrary, this does not work with will_paginate and SEARCH POST, at least not by default. If you use POST in your search method, parameters will not be passed to will_paginate.

Problem being will_paginate does not generate a form that will post, instead it generates links that will need to have params[:q] passed, which will end up being ugly as end users start moving about pagination.

This will actually get will_paginate working with POST, but the next page will then be switched to "GET" :
<%= will_paginate(@search, :params => { q: params[:q]}) %>

The way around all this is to look into will_paginate Link Rendering, and have a form with post be used to scroll through pages: https://github.com/mislav/will_paginate/wiki/Link-renderer.

Hope this can be helpful to someone.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment