title: How to group 'each do' output by parent?
body: <p>I am currently using the acts_as_tree gem and wish to display all my category names, separated by parent category names. Here is what I have tried.</p>
  
  <pre><code>&lt;% @categories.each do |category| %&gt;
  &lt;h4&gt;&lt;%= category.parent.name if category.parent %&gt;&lt;/h4&gt;
  &lt;%= category.name%&gt;
  &lt;% end %&gt;
  </code></pre>
  
  <p>It doesn't work because the parent titles are being repeated for every child. What I wish to achieve is parents only displayed once, followed by its children as such.</p>
  
  <p>Parent 1</p>
  
  <ul>
  <li>Parent 1 Child 1</li>
  <li>Parent 1 Child 2</li>
  <li>Parent 1 Child 3</li>
  </ul>
  
  <p>Parent 2</p>
  
  <ul>
  <li>Parent 2 Child 1</li>
  <li>Parent 2 Child 2</li>
  <li>Parent 2 Child 3</li>
  </ul>
  
  <p>Any help is appreciated! </p>