title: Rails 5 best controller action to write a like query
body: <p>I want to make an ajax search query by a client's name, so I'm using a like clause (<a href="https://stackoverflow.com/questions/26094430/safe-activerecord-like-query">see this question</a>). I was thinking of using the index action to respond to json format from clients_controller but I'm already using it to repond to html format and at the same time paginates my listed rows with <strong>will_paginate</strong> and <strong>will_paginate-bootstrap</strong>.</p>
  
  <p>What is the best way? making a new method to respond to json format or should I use the index one with format? and How to do that?</p>
  
  <p>I'm new with ruby on rails</p>
  
  <p><strong>clients_controller.rb</strong></p>
  
  <pre><code>def index
    respond_to do |format|
      format.html
      {
         #something like this I know that I would return me a syntax error
         @client = Client.paginate(:page =&gt; params[:page])
      }
      format.json
      {
         #something like this I know that I would return me a syntax error
         @client = Client.where("client_name LIKE ? ", "%#{params[:client_name]}%"  )
      }
    end
  end
  
  def other_method
    @client = Client.where("client_name LIKE ? ", "%#{params[:client_name]}%"  )
    respond_to do |format|
      format.json {...}
    end
  end
  </code></pre>