title: Ruby on Rails Why do I get this error message when changing the amount shown per page with multi-find?
body: <p>In my ruby on rails application I have a drop down menu on the index page where a user can change the amount of results displayed, for example changing from 6 results to 3 results. It works on the index.html.erb page when the application loads, but when the search is used and relevant results are returned changing the results shown per page I get the following error:</p>
  
  <p>TypeError in ProductsController#multi_find
     can't convert nil into String</p>
  
  <pre><code>Extracted source (around line #64):
  
  62 def self.multi_find(cat_id, search)
  63 search_price = search
  64 search_condition = "%" + search + "%"
  65 # test if cat_id is not blank
  66 if not cat_id.blank?
  67 # assign the value of cat_id to a ‘scope’ named :cat
  </code></pre>
  
  <p>This is the drop down menu in the index.html.erb file:</p>
  
  <pre><code>                &lt;div id="per-page"&gt;
                      &lt;form&gt;
                          Results per page:
                          &lt;select name="per"&gt;
                              &lt;option value="3"&gt;3&lt;/option&gt;
                              &lt;option value="6"&gt;6&lt;/option&gt;
                              &lt;option value="9"&gt;9&lt;/option&gt;
                          &lt;/select&gt;
                          &lt;button&gt;
                              Go
                          &lt;/button&gt;
                      &lt;/form&gt;
                  &lt;/div&gt;
  </code></pre>
  
  <p>This is the products_controller where the results per page is added to the index:</p>
  
  <pre><code>  def index
       @products = Product.order(:title).page(params[:page]).per(params.fetch(:per, '6').to_i)
   end
  </code></pre>
  
  <p>This is the multi_find method in the products_controller where using the drop down menu breaks:</p>
  
  <pre><code>  def multi_find
      # call a Product class method, using two parameters; a category unique identifier and a search string (author or title)
      products = Product.multi_find(params[:cat_id], params[:search_string])
      @products = Kaminari.paginate_array(products.order :title).page(params[:page]).per(params.fetch(:per, '6').to_i)
      # if no products have been found
      if products.empty?
          # display a notice
          flash.now[:alert] = "No records found - displaying all records ..." 
          # then display all products
          @products = Product.order(:title).page(params[:page]).per(params.fetch(:per, '6').to_i)
      end
      # use the index view
      render :action =&gt; "index" 
  end
  </code></pre>
  
  <p>And the product.rb multi_find method:</p>
  
  <pre><code>    def self.multi_find(cat_id, search)
      search_price = search
      search_condition = "%" + search + "%"
      # test if cat_id is not blank
      if not cat_id.blank?
          # assign the value of cat_id to a ‘scope’ named :cat 
          scope :cat, -&gt; { where('category_id = ?', cat_id)}
          # using the ‘scope’ cat find where a search string is like a title or an author’s name
          self.cat.where("title LIKE ? OR author_name LIKE ? OR price = ?", search_condition, search_condition, search_price)
      # else
      else
          # find where a search string is like a title or an author’s name
           self.cat.where("title LIKE ? OR author_name LIKE ? OR price = ?", search_condition, search_condition, search_price)
      # end
      end
  </code></pre>
  
  <p>If I completely remove the:</p>
  
  <pre><code>.per(params.fetch(:per, '6').to_i)
  </code></pre>
  
  <p>And just use .per(6) it works fine, it's only when replacing it to try and allow the user to select the amount per page with the multi_find search it breaks.</p>
  
  <p>Can anyone help? Thank you in advance.</p>