Please describe the desired behavior.
Pagy is a pagination gem used for its peak performance over other pagination tools. As mentioned #8426 we have been trying to migrate our codebase from will_paginate to pagy gem and would love your help with it! :tada:
Here is how you may implement pagy for this: -
blog under home_controllerSince here pagination is already implemented using will_paginate as .paginate(page: params[:page], per_page: 8) you can remove this line so that the method now looks like
@notes = Node.where(status: 1, type: 'note')
.includes(:revision, :tag)
.references(:term_data, :node_revisions)
.where('term_data.name = ?', 'blog')
.order('created DESC')
Now add the pagy method in this action as -
@pagy, @notes = pagy(Node.where(status: 1, type: 'note')
.includes(:revision, :tag)
.references(:term_data, :node_revisions)
.where('term_data.name = ?', 'blog')
.order('created DESC'), items: 8)
Here 8 represents the items to be displayed on each page. This is the most basic way we can use pagy over any action: -
@pagy, @records = pagy(Product.some_scope)
tag/blog.html will_paginate line and replace it with - <% if @pagy %>
<%= raw pagy_bootstrap_nav @pagy %>
<% else %>
<%= will_paginate @notes, renderer: WillPaginate::ActionView::BootstrapLinkRenderer unless @unpaginated %>
<% end %>
@pagy variable is available or not and then if present will generate pagination using pagy.Additional context (optional)
In case of queries please checkout the following links for help: -
https://ddnexus.github.io/pagy/how-to
https://ddnexus.github.io/pagy/migration-guide
https://github.com/publiclab/plots2/pull/8428
https://github.com/publiclab/plots2/pull/8326
Hey @jywarren @cesswairimu I was hoping we can use this as a template for creating hacktoberfest pagy issues but I think it might not be that clear :sweat_smile: can you check it out once? Thanks :v:
I think it is clear enough, plus we could customize each issue based on what files need to be changed
Ohh yes that's what I had in mind too :sweat_smile: so should I add the hacktoberfest label to it then?
yeah looks good. Thanks
Hey @avats-dev maybe we can use this as a template to create more issues for hacktoberfest if you are interested? Thanks :v:
@Tlazypanda Sure, looks good. :+1:
Opened #8444 based on this, check it out. Also it needs to be labelled hacktoberfest.
@Tlazypanda
Heya! I've been able to work with pagy a bit and may be able to take a shot at helping migrate. Cool if I could get assigned?
Hey @tyler-wel , sure go ahead! Happy Hacktoberfest 馃帀
@Tlazypanda
I'm actually having trouble finding out where the home#blog action is actually being hit 馃 ....
Nothing in the routes file points to home#blog and using some puts statement nothing gets logged.
Going to localhost:3000/blog is routing to tag#blog as far as I can tell.
Adding the pagy() bit to the #blog actions inside the tags controller seems to be the correct controller / route
Hey @tyler-wel Ohh yes that seems correct! :sweat_smile: must have got the wrong controller in a hurry. Please go ahead with this: :100:
Most helpful comment
Hey @tyler-wel Ohh yes that seems correct! :sweat_smile: must have got the wrong controller in a hurry. Please go ahead with this: :100: