Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

updated the page method, added args to AR page method #276

Closed
wants to merge 5 commits into from
Closed

updated the page method, added args to AR page method #276

wants to merge 5 commits into from

Conversation

hmaack
Copy link

@hmaack hmaack commented Nov 8, 2012

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

Hannes Maack added 4 commits November 5, 2012 23:51
…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
@miloops
Copy link

miloops commented Jan 9, 2013

Any chance to get this fixed? Users keep changing URL and we get lots of errors because of this... cc @mislav

@mislav
Copy link
Owner

mislav commented Jan 10, 2013

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)
begin
  posts = posts.page(params[:page])
rescue ArgumentError
  posts = posts.page(default_page)
end

Or you could massage params[:page] before you pass it in will_paginate.

@mislav mislav closed this Jan 10, 2013
@miloops
Copy link

miloops commented Jan 10, 2013

In every action in your application that uses pagination? That's not very practical.

@dgilperez
Copy link

@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?

@mislav
Copy link
Owner

mislav commented Feb 11, 2014

@dgilperez You could be handling WillPaginate::InvalidPage instead of ArgumentError.

@dgilperez
Copy link

@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)

@dgilperez
Copy link

@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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants