title: Trying to combine will_paginate gem and pg_search gem
body: <p>I'm trying to add a paginator and a search. It works fine until I add a pg_search. pg_search goes to the right URL but does not filter the search result. For example if i type Vere Lee - <a href="http://localhost:3000/admin/dashboard?utf8=%E2%9C%93&amp;search=Vera+Lee&amp;commit=" rel="nofollow noreferrer">http://localhost:3000/admin/dashboard?utf8=%E2%9C%93&amp;search=Vera+Lee&amp;commit=</a> , it would stick to the same page without filtering. If I take away paginator, pg_search seems to work fine.</p>
  
  <p>Is there a way to combine them both?</p>
  
  <p>Controller</p>
  
  <pre><code>   class AdminController &lt; ApplicationController
        before_action :require_login
        def dashboard
        @users = User.joins(:filled_documents).group("users.id").having("count(filled_documents.id) &gt; ?",0).order("created_at ASC").paginate(page: params[:page], per_page: 5).perform_search(params[:search])
      end
  </code></pre>
  
  <p>Views/dashboard</p>
  
  <pre><code>&lt;header class="title"&gt;
    &lt;h1&gt;Dashboard&lt;/h1&gt;
  &lt;/header&gt;
  
  &lt;form&gt;
    &lt;div class="grid-container"&gt;
      &lt;div class="grid-x grid-padding-x"&gt;
        &lt;div class="medium-6 cell"&gt;
          &lt;label&gt;Search Field
            &lt;%= form_tag(@users_path, method: "get") do %&gt;
            &lt;%= text_field_tag :search, nil, placeholder: "Search either company, first or last name", class: "form-control" %&gt;
            &lt;%= submit_tag "", style: "display: none;" %&gt;
              &lt;% end %&gt;
          &lt;/label&gt;
        &lt;/div&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  &lt;/form&gt;
  
  &lt;%= will_paginate @users %&gt;
  &lt;section class="wrapper"&gt;
    &lt;div class="span-10"&gt;
  
      &lt;% @users.each do |user| %&gt;
        &lt;h4&gt;&lt;a style="color: #000;" href='/admin/usershowinfo?id=&lt;%= "#{user.id}" %&gt;'&gt;&lt;%= "#{user.first_name} #{user.last_name} - #{user.company_name}" %&gt;&lt;/a&gt;&lt;/h4&gt;
        &lt;table class="table-minimal"&gt;
          &lt;thead&gt;
            &lt;tr&gt;
              &lt;th colspan=4&gt;Name&lt;/th&gt;
              &lt;th&gt;State&lt;/th&gt;
              &lt;th colspan=3&gt;Actions&lt;/th&gt;
            &lt;/tr&gt;
          &lt;/thead&gt;
  
          &lt;tbody&gt;
            &lt;% user.filled_documents.each do |filled_document| %&gt;
            &lt;tr&gt;
              &lt;td colspan=4&gt;
                &lt;%= "#{filled_document.name.empty? ? "Untitled" : filled_document.name}" %&gt; &lt;span class="badge-notice"&gt;&lt;%= filled_document.comments.count %&gt;&lt;/span&gt;
                &lt;br&gt;
                &lt;i&gt;&lt;%= filled_document.document.name %&gt;&lt;/i&gt;
              &lt;/td&gt;
              &lt;td&gt;&lt;%= filled_document.valid? ? "Complete" : "In Progress" %&gt;&lt;/td&gt;
              &lt;td colspan=3&gt;
                &lt;%= link_to 'View', document_filled_document_path(filled_document.document, filled_document), class: "btn" %&gt;
                &lt;%= link_to 'Edit', edit_document_filled_document_path(filled_document.document, filled_document) , class: "btn"%&gt;
                &lt;%= link_to 'Download', download_document_filled_document_path(filled_document.document, filled_document) , class: "btn" if filled_document.valid? %&gt;
                &lt;%= link_to 'Delete', [filled_document.document, filled_document], method: :delete, data: { confirm: 'Are you sure?' }, class: "btn" %&gt;
              &lt;/td&gt;
            &lt;/tr&gt;
            &lt;% end %&gt;
          &lt;/tbody&gt;
        &lt;/table&gt;
        &lt;hr&gt;
      &lt;% end %&gt;
  
  
    &lt;/div&gt;
  &lt;/section&gt;
  &lt;%= will_paginate @users %&gt;
  </code></pre>
  
  <p>User model</p>
  
  <pre><code>class User &lt; ActiveRecord::Base
    include Clearance::User
  
    has_many :filled_documents
  
    include PgSearch
     pg_search_scope :search,
                     against: [
                       :company_name,
                       :first_name,
                       :last_name
                     ],
                     using: {
                       tsearch: {
                         prefix: true,
                         normalization: 2
                       }
                     }
  
    belongs_to :organisation
  
    validates_presence_of :first_name, :last_name, :company_name, :phone_number
  
    def self.perform_search(keyword)
      if keyword.present?
      then User.search(keyword)
    else User.all
      end
    end
  
    def update_password newpass
      puts "user.update_password called for #{first_name} #{last_name}"
      self.password = newpass
      save(validate: false)
    end
  
    def accept_new_tnc
      return false if admin?
      latest_signup_tnc = TermsAndCondition.signup.last
      return true if self.accepted_tnc != latest_signup_tnc.pdf_hash_value
      false
    end
  
    def update_accepted_tnc
      latest_signup_tnc = TermsAndCondition.signup.last
      self.accepted_tnc = latest_signup_tnc.pdf_hash_value
      self.accepted_tnc_date = DateTime.now
      self.save
    end
  
    def accept_legal_advice
      latest_legal_advice_tnc = TermsAndCondition.legal_advice.last
      self.accepted_legal_advice = latest_legal_advice_tnc.pdf_hash_value
      self.accepted_legal_advice_date = DateTime.now
      self.save
    end
  end
  </code></pre>