Giter Club home page Giter Club logo

Comments (7)

ddnexus avatar ddnexus commented on August 25, 2024

The :page variable does not get ignored: the execution doesn't even arrive to create the Pagy instance, because the Pagy::Backend is assuming there is a params method in your controller.

Please, take a look at the Environment Assumptions for clue about why that happens and how to easily avoid it.

from pagy.

 avatar commented on August 25, 2024

From that page:

However you can force a page number by just passing it to the pagy method. For example:
@pagy, @records = pagy(my_scope, page: 3)
That will explicitly set the :page variable, overriding the default behavior (which usually pulls the page number from the params[:page]).

Doesn't this mean that I don't need a params variable/method at all, if I am always explicitly setting the page number?

from pagy.

ddnexus avatar ddnexus commented on August 25, 2024

from pagy.

ddnexus avatar ddnexus commented on August 25, 2024

In other words: you have first to satisfy the environment assumptions (which require a params method or an overridden pagy_get_vars that avoids to call it), and then if you want explicitly override the :page variable you can pass it to the pagy method. However that is for single instance overriding or variable addition.

Since you have to override the pagy_get_vars to avoid the params call, I would suggest you to set the :page in that method, which raison d'Γͺtre is exactly collecting the variables (including the :page) for the Pagy creation.

BTW, what framework are you using and where do you get the :page from?

from pagy.

ddnexus avatar ddnexus commented on August 25, 2024

You may also want to read the Pagy::Backend doc that could give you more insights about the pagy method.

from pagy.

 avatar commented on August 25, 2024

Thanks for clearing that up. I managed to set the page number by overriding pagy_get_vars so the page option is given preference, as this seems to be the only way to get it working with the framework I'm using.

I'm using Middleman and Sequel together. The page number is passed as a local variable directly to a template, and bypasses the file that overrides pagy_get_vars. That's why it wasn't clear how to set it up.

from pagy.

ddnexus avatar ddnexus commented on August 25, 2024

Glad that you made it work.

However, overriding pagy_get_vars is not the only way. You can write your own pagy method and bypass the pagy_get_* methods altogether.

For sequel you need also to override he :count assignment from collection.count(:all) to collection.count (but you should already know that by now).

from pagy.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.