title: Rails, JSON Object, jQuery, Auto-Complete
body: <p>I'm using this jquery autocomplete plug-in with rails: <a href="http://docs.jquery.com/Plugins/Autocomplete" rel="nofollow noreferrer">http://docs.jquery.com/Plugins/Autocomplete</a></p>
  
  <p>I can't figure out how to format my results, both in my Rails controller and in my javascript file.</p>
  
  <p>I have something like this in my controller...</p>
  
  <pre><code>@query = params[:q].downcase
  @json = User.all(:login =&gt; /^#{@query}/)
  respond_to do |format|
    format.js  { render :json =&gt; @json.to_json(:only =&gt; "login"), :layout =&gt; false }  
  end
  </code></pre>
  
  <p>And then this in my script.js file...</p>
  
  <pre><code>    $("#form").autocomplete('/url', {
      width: 320,
      dataType: 'json',
      highlight: false,
      scroll: true,
      scrollHeight: 300
      })
  </code></pre>
  
  <p>But I can't figure out how to parse the data, so my autocomplete just gets a raw array of all my results at once.</p>
  
  <p>How do I process the JSON in the script.js file and/or in my controller for it to work?</p>