#210 ✓invalid
Michael Economy

ignore bad page numbers

Reported by Michael Economy | April 22nd, 2008 @ 09:41 AM

its not cool how the paginate method explodes when i give it an invalid page number ( page =

I think a better approach would be to default to page 1

Also... it would also be nice if it caught the page numbers that were too large and did something nice there (like defaulting to the last page).

At the very least the will_paginate library's should be consitent if the page number is either too low or too high. Right now that behavior is different in each case.

WillPaginate::InvalidPage in HomeController#index

"three" given as value, which translates to '0' as page number

RAILS_ROOT: /Users/michael/work/topten

Application Trace | Framework Trace | Full Trace

/opt/local/lib/ruby/gems/1.8/gems/will_paginate-2.2.2/lib/will_paginate/collection.rb:51:in `initialize'

/opt/local/lib/ruby/gems/1.8/gems/will_paginate-2.2.2/lib/will_paginate/collection.rb:86:in `new'

/opt/local/lib/ruby/gems/1.8/gems/will_paginate-2.2.2/lib/will_paginate/collection.rb:86:in `create'

/opt/local/lib/ruby/gems/1.8/gems/will_paginate-2.2.2/lib/will_paginate/finder.rb:76:in `paginate'

Comments and changes to this ticket

  • Mislav

    Mislav April 26th, 2008 @ 07:20 PM

    • Assigned user changed from “Chris Wanstrath” to “Mislav”
    • State changed from “new” to “hold”

    It is supposed to bomb. It's invalid input, after all. The only way it could happen is nasty spiders or corrupted links.

    If it defaulted to page 1, then the following URLs will resolve to a same resource:

    /index?page=1
    /index?page=0
    /index?page=foobar
    /index?page=anything...
    

    I don't think that's correct behavior. When asking for an invalid page number, you should get a 404 or 500. If you were using Rails 2, you would get a 404 by default with will_paginate 2.2.2. But, with Rails 1.2 you are required to handle the InvalidPage error manually with rescue_action_in_public or something like that. You can turn it to a 404 with several extra lines in ApplicationController.

    As for page too high, right now it doesn't bomb because I haven't felt that's necessary. An empty collection is returned and there are no results displayed in the view for the user. He can then click on any of the existing page numbers.

    Any developer can make too large page numbers bomb by raising a custom error after checking WillPaginate::Collection#out_of_bounds? method.

  • Mislav

    Mislav October 7th, 2008 @ 09:34 PM

    • State changed from “hold” to “invalid”
    • Tag set to page, will_paginate

Please Sign in or create a free account to add a new ticket.

With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.

New-ticket Create new ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile ยป

Everyone's favorite Ruby library for pagination of practically anything!

Referenced by

Pages