Skip to main content

How to Add Pagination with Pagy Discussion

General • Asked by Chris Oliver

I couldn't have explained it better - even being the author of Pagy.
Thank you!


I found this gem a couple of months ago and I don't see myself going back to kaminari, really good work!


Hi chris, Domizio,

I have not managed to get pagy to work with searchkick (implemented as the searchkick episode). getting weird message as it seems to be looking for a total_count method. I am in Rails 5.2. Thks much for your help.

@pagy_s, @employees = pagy_searchkick (
  policy_scope(Employee).search(query,
    {
    misspellings: {fields: [:department]},
    order: {created_at: :desc},
    load: true,
    per_page: 40
  }


        I have some results. trouble is that my policy_scope from pundit does not apply anymore if i do this.

following this note from Stephen Dolan, I did something which provides the results but...to be fair it is dirty...(and i don't know what i am doing!)

query = params[:search].presence || "*"
@pagy_s, @employees = pagy_searchkick (
  policy_scope(Employee).search(query,
    {
    misspellings: {fields: [:department]},
    order: {created_at: :desc},
    load: true,
    per_page: 40,
    scope_results: ->(r) { r.where(id: policy_scope(Employee).pluck(:id)) }
  }
)

)

And the pagination from pagy does not work anymore...:-(

Think I have an issue. Appreciate is someone could help to combine 3 things:

  • pagy
  • searchkick
  • pundit probably never heard off outside Gorails but Chris is introducing too much nice gems. Question: how to make them work together.

The searchkick extra has been refactored in pagy v2.0. If you need more support, please use the gitter chat. Thanks.


Pagy is awesome, I've included it on my site.


Thank you for this wonderful explanation. The Pagy docs don't mention the requirement that you need to 'import' the methods for front end and back end. This video was the missing link. Thank you once again Chris for a job well done!

I certainly agree with the "Chris... job well done": indeed I couldn't have explained it better, but let me point out that the Pagy docs does mention it everywhere it makes sense:

Hi Domizio,

Thank you for this. My team and I only found the Quick Start doc. We must have missed the other docs. If you haven't already, perhaps post these four links prominently at the top of the read me? Maybe they are there, but we couldn't get it to work until we watched Chris' video. Not a criticism: just helpful (we hope) feedback from actual users. We love Pagy and thank you so much for creating it!

-Monroe
BreakDiving.io


Pagy 3.0 is out!
Now ~40x faster, ~36x lighter!
Take a look at the charts ;)

Oh that's exciting! Since we just got the prior version working, will it be easy to upgrade? Do you recommend we do so, or stick with what we now have working? Thanks Domizio.

They did change some stuff around specially if you are using searchkick


Monroe, 3.0 is better than 2.0 and 1.0, obviously :)
Depending on what you used in 2.0, you might be OK even without changing anything in your code, and if you have to change something it will probably be just search and replace, (some method and variable have been renamed). Please, check the CHANGELOG for complete details.
The elasticsearch extras refactoring mentioned by Tabish happened in 2.0, and 3.0 didn't touch it.


Login or Create An Account to join the conversation.

Subscribe to the newsletter

Join 24,647+ developers who get early access to new screencasts, articles, guides, updates, and more.

    By clicking this button, you agree to the GoRails Terms of Service and Privacy Policy.

    More of a social being? We're also on Twitter and YouTube.