title: Rails 3 Return Array From Collection.each Block
body: <p>I'm trying to return some json to the calling action. One of the params I want to pass is an array of arrays built from looping through a collection as so: </p>
  
  <pre><code>render :json =&gt; {     
  :rows =&gt; @classrooms.each do |classroom|
            [classroom.name, classroom.students.count]
          end    
  }  
  </code></pre>
  
  <p>However, this sets :rows to the entire collection as opposed to what I want:</p>
  
  <blockquote>
    <p>[[classroom, students],[classroom, students],[classroom, students]]</p>
  </blockquote>
  
  <p>Is there any way of looping through the collection and returning an array in a single block?</p>