title: grouping children by parent attribute
body: <p>Here's what I am trying to achieve:</p>
  
  <h2>Group_x.name</h2>
  
  <p>member1.name -- member1.join_date -- etc<br>
    member2.name -- member2.join_date -- etc 
    ...</p>
  
  <h2>Group_y.name</h2>
  
  <p>member1.name -- member1.join_date -- etc<br>
    member2.name -- member2.join_date -- etc 
    ...</p>
  
  <p>What I'm going for is really very similar to <a href="https://stackoverflow.com/questions/2971465/grouping-comments-by-parent-object-ordering-parent-object-by-oldest-comment">this</a> although the implementation there doesn't work for me.  </p>
  
  <p>I've gotten this far in my controller: </p>
  
  <pre><code>def index
    # https://stackoverflow.com/a/17835000/2128691
    @user_group_ids = current_user.student_groups.map(&amp;:id)
    @students = Student.where('student_group_id IN (?)', @user_group_ids)
    # https://stackoverflow.com/a/10083791/2128691
    @students_by_group = @students.uniq {|s| s.student_group_id}
    @title = "All students"
  end  
  </code></pre>
  
  <p>and calling the following in my view - </p>
  
  <pre><code>&lt;% @students_by_group.all.each do |x| %&gt;
    &lt;p&gt;
      &lt;%= "#{x}" %&gt;
    &lt;/p&gt;
  &lt;% end %&gt;   
  </code></pre>
  
  <p>gives me a list of all <code>student</code> objects.  if i call <code>&lt;%= "#{x.name}" %&gt;</code> or <code>&lt;%= "#{x.created_at}" %&gt;</code>, etc, I get the correct information, and everything is great. </p>
  
  <p>But now that I have all this information, how can I put the group.name (in my code it would be <code>x.student_group.name</code>) as a header for all of the students for which that group_name is true?</p>