Ask A Question

Notifications

You’re not receiving notifications from this thread.

How to Add Pagination with Pagy Discussion

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

Reply

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

Reply

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.

Reply

Hey Stan X,

Check out the pagy_searchkick extra - https://ddnexus.github.io/pagy/extras/searchkick

Reply
@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.
Reply

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)) }
  }
)

)

Reply

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.
Reply

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

Reply

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

Reply

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!

Reply

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:

Reply

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

Reply

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

Reply

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.

Reply

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

Reply

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.

Reply

Pagy is awesome, do we have a tailwindcss plugin for stylling @chris

Reply

Thank you Chris, for another awesome and clear explanation. And thank you Domizio for making Pagy.

👏

Reply

If we are counting records, ie. <%= index + 1%> how can we keep the count going when we we navigate to the next page? Currently my next page starts at 1 again.

Reply

Hi everyone. I just installed pagy and it's working fine, but I'm having a problem with the bootstrap extension. When I create the pagy.rb and add this line of code: require 'pagy/extras/bootstrap'

I'm having this error: "`require': cannot load such file -- pagy/extras/bootstrap (LoadError)". Anyone knows what could be the problem here?

Thanks!

Reply

Thanks. Got working without any problems with Rails 7.0.1, Ruby 3.1.0, esbuild and Bootstrap

@newbie. Did you create ` in config/initializers/pagy.rb' in the right place? Restart server?

Reply
Join the discussion
Create an account Log in

Want to stay up-to-date with Ruby on Rails?

Join 87,400+ developers who get early access to new tutorials, screencasts, articles, and more.

    We care about the protection of your data. Read our Privacy Policy.