title: Group multiple entries by a column in a collection
body: <p>I have a collection of records I am showing in a table within a view file that looks as follows:</p>
  
  <pre><code>|| user || sport || # of victories || # of losses ||  
  || Jane || foo   ||       1        ||      1      ||  
  || Jane || foo   ||       2        ||      3      ||  
  || Jane || bar   ||       1        ||      1      ||  
  || Jane || bar   ||       2        ||      3      ||
  </code></pre>
  
  <p>In the example above, I am trying to group the results based on the sport, so rather than having the 2 records  </p>
  
  <pre><code>|| Jane || foo   ||       1        ||      1      ||  
  || Jane || foo   ||       2        ||      3      || 
  </code></pre>
  
  <p>There would be a single grouping, which is currently broken up into multiple entries based on another column I'm not displaying on this view.</p>
  
  <pre><code>|| Jane || foo   ||       3        ||      4      ||  
  </code></pre>
  
  <p>I've been trying .group and .group_by to accomplish this, but don't seem to be doing this correctly. Can someone please provide some pointers? </p>
  
  <p>Additional info, if needed:</p>
  
  <p>Table schema  </p>
  
  <pre><code>create_table "records", force: :cascade, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8" do |t|
   t.integer "victories"
   t.integer "losses"
   t.bigint "user_id"
   t.bigint "sport_id"
   t.datetime "created_at", null: false
   t.datetime "updated_at", null: false
   t.integer "opposition_id"
   t.index ["opposition_id"], name: "index_records_on_category_id"
   t.index ["user_id"], name: "index_records_on_user_id"
  end
  </code></pre>
  
  <p>Controller</p>
  
  <pre><code>  def board
      @summary = Record.all.sort_by{ |i| i.user_id }
    end
  </code></pre>
  
  <p>View</p>
  
  <pre><code>   &lt;% @summary.each do |record| %&gt;
       &lt;tr&gt;
        &lt;td&gt;&lt;%= record.user.name %&gt;&lt;/td&gt;
        &lt;td&gt;&lt;%= record.sport_id %&gt;&lt;/td&gt;
        &lt;td&gt;&lt;%= record.victories %&gt;&lt;/td&gt;
        &lt;td&gt;&lt;%= record.losses %&gt; &lt;/td&gt;
      &lt;/tr&gt;
     &lt;% end %&gt;
  </code></pre>