GitHub is home to over 20 million developers working together to host and review code, manage projects, and build software together.
If the :page variable is nil it defaults to 1. Yet you're still required to pass it.
Why is this? Not passing any judgement either way, just seems like a weird api.
I'm going to monkey-patch mine to not do this, but am wondering if there's something I'm missing.
I've had this thought a couple times now. But then I remember that nil means that :page => params[:page] was passed and there was no page parameter to the url. But no :page parameter at all probably means I forgot it. Certainly there are cases where this isn't true, but I think this is a little defensive programming that has saved countless cumulative hours of debugging.
That's what I assumed it was for (the defensive programming thing), but still feels kind of weird to me. Maybe it's one of those things where a config var should toggle it, or a config var should set the default.
I'd be happy to build either if anyone else think's that's useful.
Btw, by default I meant something like:
raise "defensive" if no page argument passed && WillPaginate.default_page.nil?
Chris is right. As for the proposed configuration variable: I only add configuration options for features I expect widespread usage of, and I don't want widespread usage of hardcoding ":page" to "1".
Advanced users can set their own behavior by overriding WP::Collection or creating helper methods that wrap #paginate or other methods.