Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8774837
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T18:40:06+00:00 2026-06-13T18:40:06+00:00

I am using Kaminari to handle pagination. I recently found out that a lot

  • 0

I am using Kaminari to handle pagination. I recently found out that a lot of bogus request is requesting an invalid page number, such as /post/page/undefined. Since I am using Solr, bad page number got passed into it and cause 500 error.

I want to be able to validate the page number, before it gets passed to the controller. So invalid page number will cause routing error instead.

I have asked the creator of Kaminari, and he gave a temporary solution. However I am wondering if there are cleaner ways to do this. I also don’t want to include this logic in every paginable resource, as that will be not DRY at all.

My route example:

resources :transactions do
  get 'page/:page', :action => :index, :on => :collection
end
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T18:40:07+00:00Added an answer on June 13, 2026 at 6:40 pm

    I think a good solution is to simply remove or correct any invalid or frivolous page parameters and redirect to the corrected URL, like so:

    # This goes in your relevant controller(s)
    before_filter :correct_page_parameters!
    
    # This goes in your application controller
    def correct_page_parameters!
      supplied_parameters = params[:page]
      if supplied_parameters        
        proper_parameters = supplied_parameters.to_i
    
        if proper_parameters < 2
          params.delete(:page)
          redirect_to params
        elsif supplied_parameters != proper_parameters.to_s
          redirect_to params.merge(:only_path => true, :page => proper_parameters)
        end
      end
    end
    

    Hope this helps, good luck!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using pjax for main navigation and pagination (kaminari). Within the page I
Am using kaminari ajax pagination in my project. It is working fine, But contents
Rails -v 3.2.3 im using kaminari to do pagination but i keep getting a
I'm using the gem called 'acts_as_follower' and 'kaminari' . If I put .page(params[:page]).per(10) in
I am using plugin Kaminari for pagination. I am Ajaxifing my application and I
I'm using a Rails 3 App with Kaminari for Pagination. Because of my language,
I am using Kaminari for pagination and trying to use meta_search for column ordering.
I am using Mongoid with Kaminari for pagination and it is working fine for
I'm using the kaminari gem for pagination. I want to only show the 10
I'm using Rails 3.2 and Kaminari for pagination. I'm using the same controller action

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.