title: Doing search by count in json with params results
body: <p>I'm trying to implement a counter filter in my json. When I access the url <code>api/v1/contacts?Results=2</code> [sic], I would like to get only two results from my json.</p>
  
  <p>For this, I created two methods in my controller: an index that takes the information from the database and turns render into json, and a method that returns the number of times the json is returned.</p>
  
  <pre><code>class Api::V1::ContactsController &lt; ApplicationController
  
    before_action :results, only: [:index]
  
    def index
      @contacts = Contact.all
      render json: {results: @contacts[0..@number_results]}
    end
  
  
    def results
      if params[:results]
        results = params[:results]["results"]
        @number_results = results.to_i
      else
        @number_results = 3
      end
    end
  end
  </code></pre>
  
  <p>Regardless of the value entered for <code>results =</code>, the value of <code>@number_results</code> is set to <code>0</code>, so whenever I type <code>results = I</code>, get only the first result of json. If I do not type <code>results =</code> in the url, it sets <code>@number_results</code> to <code>3</code>, and shows four results on the screen.</p>
  
  <p>Can anyone help?</p>