In my fork its possible to set a default_page as a argument for the page method. If param[:page] is invalid, the page method would return the default_page and is not raising an exception, like it is now for the issue #271
params[:page] = 'foobar'
posts = Post.where(:published => true).page(params[:page])
#posts.current_page = 1
# set default_page if necessary
posts = Post.where(:published => true).page(params[:page], :default_page => 10)
#posts.current_page = 10
# this raises no exception, it trys to return the default_page
with best regards
get page number one for invalid page_numbers
reverted page_number.rb to original, added args to page method for ac…
…tive-record, now its possible to add default_page param e.g. page('foo', :default_page => 2) to get no exception in case of invalid pagenum ("foo") and to set a default page if its not page one
changed read me for docu
fixed read me
changed active_record spec test
Any chance to get this fixed? Users keep changing URL and we get lots of errors because of this... cc @mislav
Nope, I don't find the feature useful. The exception is deliberate so you can handle it in your application.
posts = Post.where(:published => true)
posts = posts.page(params[:page])
posts = posts.page(default_page)
Or you could massage params[:page] before you pass it in will_paginate.
In every action in your application that uses pagination? That's not very practical.
@mislav I think I could handle that exception in our apps if it would be different from the too common ArgumentError. What about raising a custom exception?
@dgilperez You could be handling WillPaginate::InvalidPage instead of ArgumentError.
@mislav hmm that's exactly what I'd rather do, but the exceptions in my controllers look like ArgumentError: invalid value for Integer(): "vdpcaglxx" (sorry, I just realized I should have commented in #271, not here)
ArgumentError: invalid value for Integer(): "vdpcaglxx"
@mislav sorry for being too fast on that. Peeping on the code I see InvalidPage as a module that tags that exception ... not used to that pattern, but I it works. Thanks!