Code Monkey home page Code Monkey logo

Comments (9)

ddnexus avatar ddnexus commented on May 19, 2024

That's weird. Did you override some method?

from pagy.

MSeneadza avatar MSeneadza commented on May 19, 2024

Here's all the code I've added or modified for Pagy.

In my controller:

  def index
    <SNIP>
    @pagy, @equities = pagy(Equity.search(@search_params))
  end

  def pagy_get_vars(collection)
    { count: collection.count(:all) }
  end

In my view:

= pagy_nav_bootstrap(@pagy).html_safe

(I also tried = pagy_nav(@pagy).html_safe with the same result`

In my helper:

  def pagy_url_for(n)
    params = request.query_parameters.merge(anchor: 'results_section', page: n)
    url_for(params)
  end

from pagy.

MSeneadza avatar MSeneadza commented on May 19, 2024

Oh, and if it makes a difference, I'm running Pagy 0.6.0 instead of 0.7.0. I had to downgrade to 0.6.0 when I installed the pagy-extras gem due to:

pagy-extras was resolved to 0.1.2, which depends on
      pagy (~> 0.6.0)

from pagy.

ddnexus avatar ddnexus commented on May 19, 2024

I see. With the overriding of pagy_get_vars you are actually wiping out the page: params[:page], so pagy will always point to page number 1.
You should not override that method and I suspect all will work as expected. Or if you really have to, ensure you will leave the :page variable in the returned hash

from pagy.

ddnexus avatar ddnexus commented on May 19, 2024

I will fix the pagy-extra dependency error with the next push tomorrow. Thanks.

from pagy.

MSeneadza avatar MSeneadza commented on May 19, 2024

@ddnexus Thanks! Adding page: params[:page] back to pagy_get_vars fixed this problem. FYI, I had to override that method because the count that was called caused a PostgreSQL error. I have to do count(:all) in several places in my app to avoid that SQL issue.

from pagy.

ddnexus avatar ddnexus commented on May 19, 2024

Good to know then. I am not very familiar with PostgreSQL: is that the way you are supposed to write it, or is that the fix for a problem with the adapter or the version or something else?

from pagy.

MSeneadza avatar MSeneadza commented on May 19, 2024

There's a brief discussion about it here https://stackoverflow.com/questions/18252570/rails-difference-between-model-count-and-model-countall

I guess you can call it a quirk between Rails and Postgres. With certain queries the count SQL statement Rails produces (something like count(col 1, col2, col3...) causes an exception in PG. So using count(:all) makes Rails issue a simple count(*)...

Here's one I hit a few hours ago while converting from Kaminari to Pagy:

ActiveRecord::StatementInvalid: PG::UndefinedFunction: ERROR: function count(character varying, character varying, timestamp without time zone) does not exist
LINE 1: SELECT COUNT(url, title, published_at) FROM "articles" WHERE...
^
HINT: No function matches the given name and argument types. You might need to add explicit type casts.
: SELECT COUNT(url, title, published_at) FROM "articles" WHERE "articles"."equity_id" = $1

from pagy.

ddnexus avatar ddnexus commented on May 19, 2024

Thanks for explaining that.

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.