title: Ruby on Rails: getting 404 not found error, when going to next page after search, using pg_search and will_paginate
body: <p>I'm facing a strange error, where going to next page after search will cause 404 not found error. But the pagination works well if I don't search.</p>
  
  <p>routes.rb</p>
  
  <pre><code>resources :activities do
    post :search, on: :collection
  end
  
  match "/403", to: "errors#error_403", via: :all
  match "/404", to: "errors#error_404", via: :all
  match "/422", to: "errors#error_422", via: :all
  match "/500", to: "errors#error_500", via: :all
  
  get :ie_warning, to: 'errors#ie_warning'
  get :javascript_warning, to: 'errors#javascript_warning'
  get :pwreset, to: "pages#pwreset"
  get :activities, to: "activities#index"
  get :home, to: "pages#home"
  root to: "pages#home"
  </code></pre>
  
  <p>controller.rb</p>
  
  <pre><code>@@page_size = 3
  # GET /activities
  def index
    @activities = Activity.paginate(:page =&gt; params[:page], :per_page =&gt; @@page_size)
  end
  
  # POST /products/search
  def search
    if params[:search][:title].present?
      @activities = Activity.search_activities(params[:search][:title]).paginate(:page =&gt; params[:page], :per_page =&gt; @@page_size)
      render :index
    else
      @activities = Activity.paginate(:page =&gt; params[:page], :per_page =&gt; @@page_size)
    end
  
  end
  </code></pre>
  
  <p>html.haml</p>
  
  <pre><code>- @activities.each do |activity|
  .row
    .col-md-8
      = link_to activity.title, activity
    .col-md-2
      %p= activity.publisher
    .col-md-2
      %p= activity.created_at.to_date
  
  .force-to-bottom
    .text-center
      = will_paginate @activities
  
  
  = simple_form_for :search, url: search_activities_path, method: :post do |f|
  
    .form-inline
      = f.input :title, label: false, placeholder: 'search...'
  
      = button_tag(type: 'submit', class: "btn btn-primary") do
        %span.glyphicon.glyphicon-search{"aria-hidden" =&gt; "true"}
  
      %span.glyphicon.glyphicon-remove{"aria-hidden" =&gt; "true"}
      = link_to 'clear filter', activities_path
  </code></pre>
  
  <p>error message</p>
  
  <pre><code>Started GET "/activities/search?page=2" for ::1 at 2018-04-16 04:39:57 +0100
  Processing by ActivitiesController#show as HTML
  Parameters: {"page"=&gt;"2", "id"=&gt;"search"}
  Activity Load (17.9ms)  SELECT  "activities".* FROM "activities" WHERE "activities"."id" = $1 LIMIT $2  [["id", 0], ["LIMIT", 1]]
  Rendering errors/error_404.html.haml within layouts/application
  Haml::TempleEngine: Option :ugly is invalid
  Rendered errors/error_404.html.haml within layouts/application (6.2ms)
  Haml::TempleEngine: Option :ugly is invalid
  Haml::TempleEngine: Option :ugly is invalid
  Rendered layouts/_environment_notice.html.haml (2.0ms)
  Completed 404 Not Found in 245ms (Views: 162.2ms | ActiveRecord: 74.7ms)
  </code></pre>
  
  <p>any one can help please, I still really don't know what is going on with that error after a few hours of research</p>