Giter VIP home page Giter VIP logo

Comments (7)

benkoshy avatar benkoshy commented on May 26, 2024 1

The Cause

I suspect this is caused here:

DEFAULT[:url] = 'http://www.example.com/subdir'

We are modifying the hash after it's been frozen.

Proposed Solution

  • Just document it?

from pagy.

benkoshy avatar benkoshy commented on May 26, 2024
#pagy.rb
# Pagy initializer file (6.0.0)                                # default
Pagy::DEFAULT[:items] = 15 # default

Pagy::DEFAULT[:metadata] = %i[ first_url page_url prev_url next_url last_url ]

Pagy::I18n.load({ locale: 'de', filepath: 'config/locales/pagy-de.yml' },
                { locale: 'en', filepath: 'config/locales/pagy-en.yml' })

# When you are done setting your own default freeze it, so it will not get changed accidentally
- Pagy::DEFAULT.freeze
+ # Remove the default freeze line

from pagy.

ddnexus avatar ddnexus commented on May 26, 2024

The Pagy::Console is meant to supply a mock environment to pagy, so it would work even without any app or configuration. If you actually want to just try pagy in its mock environment, you could just use irb for a quick glance into pagy (without loading the rails env).

The use of Pagy::Console in the rails c is kind of hybrid. When you use the rails console, you are loading the rails environment (and the pagy.rb initializer/configuration), hence you should be able to use pagy without the Pagy::Console, by just running your own controllers and helpers in the console for a truthy/non-mocked output.

However if you actually want to use it in the rails c you can temporarily comment out the Pagy::DEFAULT.freeze , so allowing Pagy::Console to set the DEFAULT[:url], or set it yourself to nil in the console, in order to avoid changing the default pagy_url_for behavior.

I don't know whether using it with rails c would provide any advantage compared to use the actual controller/helper methods. If it does, please let me know. If it doesn't we should remove the rails console mention from the Pagy::Console doc and eventually add a note explaining that there is no point to use it with an app environment.

from pagy.

aslam avatar aslam commented on May 26, 2024

Temporarily commenting out the Pagy::DEFAULT.freeze line works. Thanks for the tip.

I was trying out a few things in setting the JSON response of the collection serializer using the pagy_metadata. I Thought Pagy::Console would be handy here and believe it would be.

Would there be a better way to make this module readily useful in rails c? Any ideas on what could be possible if you believe this module is useful to stay? I could try and put something for you to have a look at.

from pagy.

ddnexus avatar ddnexus commented on May 26, 2024

Would there be a better way to make this module readily useful in rails c?

Pagy is agnostic, so no rails outside of the doc.

Any ideas on what could be possible if you believe this module is useful to stay? I could try and put something for you to have a look at.

I don't understand anything of what you mean here 🙃

from pagy.

ddnexus avatar ddnexus commented on May 26, 2024

My thoughts about rais env so far are that either you need the whole rails env to check the real pagy output, and in that case you don't need Pagy::Console because you have everything accessible in the rails c, OR you just want to play with a mocked env in order to familiarize with the pagy stuff, and in that case you don't need the rails env, hence irb would be enough.

Mixing environments would just be confusing and would require more setup work than what you may save typing IMO.

Am I missing anything?

from pagy.

benkoshy avatar benkoshy commented on May 26, 2024

Closing in favour of #483.

Pls LMK if I've missed the mark. I've also simplified the wording.

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.