title: How to do a double iterate
body: <p>We have a class schedule. In <code>@appointments_monday</code>, we have different <code>appointment</code> that belongs to a specific <code>category</code>:</p>
  
  <p><img src="https://i.stack.imgur.com/DiD9o.jpg" alt="enter image description here"></p>
  
  <p>Certainly, <code>@appointment.each</code> would not work. It will produce something like:</p>
  
  <p><img src="https://i.stack.imgur.com/JZyOR.jpg" alt="enter image description here"></p>
  
  <p>because some appointment of a certain category could be empty. We're trying to loop through <code>@categories</code> to judge each <code>appointment</code>, but it turns out like this:</p>
  
  <p><img src="https://i.stack.imgur.com/67xS4.jpg" alt="enter image description here"></p>
  
  <pre><code>    &lt;% @appointments.each do |appointment| %&gt;
          &lt;% @categories.each do |category| %&gt;
              &lt;% if appointment.category == category %&gt;
                &lt;%= appointment %&gt;  
              &lt;% else %&gt;
                  placeholder
              &lt;% end %&gt;    
         &lt;% end %&gt;
      &lt;% end %&gt;
  </code></pre>
  
  <p>I think the problem is that <code>@categories.each</code> is looped over every time. How should we deal with this?</p>