Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
  • Sep 14 22:19
    ddnexus commented #406
  • Sep 14 22:18
    ddnexus commented #406
  • Sep 14 21:38
    edeesis edited #406
  • Sep 14 21:36
    edeesis opened #406
  • Aug 18 15:20
    elliotlarson commented #404
  • Aug 18 01:33
    benkoshy commented #405
  • Aug 18 01:32
    ddnexus commented #405
  • Aug 18 01:32
    ddnexus closed #405
  • Aug 18 00:51
    evgenyneu edited #405
  • Aug 18 00:50
    evgenyneu edited #405
  • Aug 18 00:50
    evgenyneu opened #405
  • Aug 18 00:45
    ddnexus commented #404
  • Aug 17 15:04
    elliotlarson commented #404
  • Aug 16 04:26
    elliotlarson closed #403
  • Aug 16 04:26
    elliotlarson commented #403
  • Aug 16 04:24
    elliotlarson opened #404
  • Aug 16 03:40
    elliotlarson synchronize #403
  • Aug 15 11:44
    benkoshy commented #403
  • Aug 14 17:53
    elliotlarson opened #403
  • Aug 12 21:50
    elliotlarson commented #401
Domizio Demichelis
@ddnexus
@benbws I think the number_of_documents cannot be used as the query count, but only as the collection count. That would be useful only in case you are paginating the full collection
Ben Greensmith
@benbws
@ddnexus Yes, I see what you mean, that's interesting, I've had a further read of the Meilisearch documentation and essentially showing the count of a search is simply not something they support. They do say that you can of course use the altered 'estimatedTotalHits' but it comes with a lot of caveats.
Domizio Demichelis
@ddnexus
I did not know that. I received a contribution and I just adjusted some details... I think I will add that to the doc.
I will leave the implementation as is ATM, just adding the compatibility to the renaming.
If we want to disable the rendering of the pages, I think that passing size: []would just render the buttons, so it would be compliant with the recommended way
Ben Greensmith
@benbws
No problem, would you still like me to create an issue to fix the current implementation because of the breaking API changes? I've got a pagy_bare_rails.rb with the error reproduced ready to go if needed.
I think as it's only a recommendation/guidance not to use the estimatedTotalHits and it would likely affect a lot of people currently using the Meilisearch extension I agree that just adding to the docs for now is the way forward.
Ben Greensmith
@benbws
I'll go ahead and submit the issue as I can't see any PR's etc
tkhobbes
@tkhobbes
Hi there, I am running pagy in a Rails 7 project and get an error when I run the spec for the index view where Pagy is visible. What do I need to do to ensure pagy works with RSpec?
Domizio Demichelis
@ddnexus
@tkhobbes review your code, because pagy has nothing to do with the way you test
tkhobbes
@tkhobbes
Hmm - don't I need to somehow tell rspec about pagy? I get this error when testing the index view: Failure/Error: <%== pagy_nav(@pagy) %>
 ActionView::Template::Error:
   undefined method `prev' for nil:NilClass

         p_prev      = pagy.prev
                           ^^^^^
Domizio Demichelis
@ddnexus
That means that your test did not set @pagy
tkhobbes
@tkhobbes
yes understood - if I add the normal @pagy expression, I get an error about "method pagy not found":
before(:all) do
@pagy, @books = pagy(Array.new(3) { create(:random_book) })
end
 Failure/Error: @pagy, @books = pagy(Array.new(3) { create(:random_book) })

 NoMethodError:
   undefined method `pagy' for #<RSpec::ExampleGroups::BooksIndexHtmlErb before(:context) hook>
   Did you mean?  pagy_t
Domizio Demichelis
@ddnexus
The pagy method must be imported from Pagy::Backend. Suggestion: You should read at least the basic doc before using any gem.
Alex Kaminetzky
@kaminetzky
Hey everybody! I'm adding Pagy to my meal logging app for calendar pagination. Has anybody implemented a way to link to the last calendar page (last year, month, and day) or to today's date? Both a "Today" button or the last page being the default one work for me.
Alex Kaminetzky
@kaminetzky
Managing to configure Pagy to default to the last page will do the job :)
Domizio Demichelis
@ddnexus
Hi @kaminetzky. That feature is implemented in the dev branch

pagy_calendar_url_at(@calendar, time)

This helper takes the @calendar and a TimeWithZone objects and returns the url complete with all the params for the pages in each bars that include the passed time.

For example: pagy_calendar_url_at(@calendar, Time.zone.now) will select the the bars pointing to today. You can see a working example in the pagy_calendar_app.ru file.

If time is outside the pagination range it raises a Pagy::Calendar::OutOfRangeError

(Copied from the dev doc. The link is referring to the dev branch)
Alex Kaminetzky
@kaminetzky
That's exactly what I need. Thanks a lot, Domizio!
Thank you for such an amazing gem :)
Domizio Demichelis
@ddnexus
@kaminetzky it is ready to be used from the branch, but it will be released with pagy 6. If possible, please post the link of your app/implementation when ready. Thank you!
Alex Kaminetzky
@kaminetzky
Gotcha! I ended up implementing a helper method for going to the last page but will definitely replace it with the new methods when they come out. Pagy is working flawlessly on my app. I'll post a link when that feature is ready :)
scott tallarida
@stallarida
Hello! Having trouble with a query that works without error UNTIL wrapped in Pagy syntax.

When wrapped in pagy I suddenly get an association error...namely: "Can't join 'Answer' to association named 'questions'; perhaps you misspelled it?"

working query:

'JobEntry.getEntriesWithImages.includes(:agency, entity: [answers: :questions]).where(:job_id => @job_id, entity: {answers: {questions: {:job_id => @job.id}}}, :job_role_id => params['role_id']).distinct.order(:created_at)'

no errors. when wrapped in pagy as:

'@pagy, @entries2 = pagy(JobEntry.getEntriesWithImages.includes(:agency, entity: [answers: :questions]).where(:job_id => @job_id, entity: {answers: {questions: {:job_id => @job.id}}}, :job_role_id => params['role_id']).distinct.order(:created_at), items:10)'

I get the error....making me nutz!

Ben Koshy
@benkoshy

When wrapped in pagy I suddenly get an association error...namely: "Can't join 'Answer' to association named 'questions'; perhaps you misspelled it?"

working query:

'JobEntry.getEntriesWithImages.includes(:agency, entity: [answers: :questions]).where(:job_id => @job_id, entity: {answers: {questions: {:job_id => @job.id}}}, :job_role_id => params['role_id']).distinct.order(:created_at)'

no errors. when wrapped in pagy as:

'@pagy, @entries2 = pagy(JobEntry.getEntriesWithImages.includes(:agency, entity: [answers: :questions]).where(:job_id => @job_id, entity: {answers: {questions: {:job_id => @job.id}}}, :job_role_id => params['role_id']).distinct.order(:created_at), items:10)'

I get the error....making me nutz!

I have no idea. Will it be too troublesome to reproduce the error here: https://github.com/ddnexus/pagy/blob/master/apps/pagy_bare_rails.rb

?
Domizio Demichelis
@ddnexus
@stallarida first, please create a scope in your model that will return an AR relation. Something that you can use like MyModel.my_scope(args) => <AR relation>
After that, try in the console if MyModel.my_scope(args).count work as expected
Then try MyModel.my_scope(args).offset(0).limit(10)
At this point you should have probably got your error without even mentioning pagy
laptopmutia
@laptopmutia

this taken from example
<%== render partial: 'pagy/nav', locals: {pagy: @pagy} %>

where to get this pagy/nav file?

is this ? https://github.com/ddnexus/pagy/blob/master/lib/templates/nav.html.erb
laptopmutia
@laptopmutia
dude pagy is the best even though the tempalte not using normal standard html erb formatting though
Ben Koshy
@benkoshy
Don't forget to require the extra
Ed Mitchell
@edeesis
Hello! I opened an issue with the minimum required for the items parameter: ddnexus/pagy#406 We'd like to set it to 0 so we can query the total count of records without querying the records themselves.
Ben Koshy
@benkoshy

Hello! I opened an issue with the minimum required for the items parameter: ddnexus/pagy#406 We'd like to set it to 0 so we can query the total count of records without querying the records themselves.

I'm not sure I follow / understand. To avoid the XY problem would you be able to elaborate on your specific use case: "so we can query the total count of records without querying the records themselves" ? Without understanding further, perhaps it can be solved outside pagy? but if pagy is required, my immediate knee jerk reaction (probably erroneous) might be to override this method: the setup_items_varmethod - the gearbox extra would be doing this internally. I think the maintainer will be unable to answer for perhaps a few days, so might be a while till you get an actual authoritative answer.

6 replies
Maciej Wicher
@wichru
Hi! I don't know maybe I'm missing something or I'm just stupid. I'm using Pagy in my Rails 7 app and the pagination works as expected. Now I want to give ability to select how many items are displayed in the list. Regarding to the docs all I need is to add require 'pagy/extras/items' into initializers/pagy.rb then in my view I should be able to use <%== pagy_items_selector_js(@pagy)%> and that's how I did. Unfortunately it doesn't do anything i.e. if I type any number other than the default number (20) nothing happens, results on the list do not change.

Here is my controller, don't know should I update it in some way?

class PaymentsController < ApplicationController
  def index
    @pagy, @payments = pagy_array(payments_array)
  end
end

Even when I change it to pagy_array(payments_array, items: params[:items]) nothing changed

Maciej Wicher
@wichru
Should I do some extra things to make it work? I've tried to disable turbo but it didn't work either
Ben Koshy
@benkoshy
@wichru Sounds like you've set up everything except javascript: https://benkoshy.github.io/pagy/docs/api/javascript/setup/ if you're using the *js selector then the javascript needs to be initialised (see the link pasted).................we've done a lot of work on improving the docs - so if you have any suggestions on how to improve it - please comment
looks like you missed it? were the docs not clear?
Zil Norvilis
@zilton7
Hi! I am facing a weird issue. Everything works fine locally but on heroku it complains about 'pagy_bootstrap_nav', I did restart heroku and still nothing. Any ideas?
Ben Koshy
@benkoshy

Hi! I am facing a weird issue. Everything works fine locally but on heroku it complains about 'pagy_bootstrap_nav', I did restart heroku and still nothing. Any ideas?

@zilton7 how can anyone give you a definitive answer? Did you require the bootstrap extra on the branch you pushed to heroku? I'd need a sample application to demonstrate the problem. I'm using a bootstrap nav for one of my apps, works fine, even on heroku.

Jarrett Lusso
@jclusso
is there any sort of pagy by id for mongo
i know there is countless but I'm loking for the most efficient way to paginate large mongoid collections and to do that would be using the id since skip is not ideal once you start skipping like 100k
Ben Koshy
@benkoshy

is there any sort of pagy by id for mongo

"pagy by id"? Pagy basically takes a collection. You would typically need things like count, items, page number -- but you would not typically need id. Unfortunately, I haven't used mongoid so I cannot comment further.