How to do a double iterate
We have a class schedule. In @appointments_monday, we have different
appointment that belongs to a specific category:
Certainly, @appointment.each would not work. It will produce something like:
because some appointment of a certain category could be empty. We're
trying to loop through @categories to judge each appointment, but it turns
out like this:
<% @appointments.each do |appointment| %>
<% @categories.each do |category| %>
<% if appointment.category == category %>
<%= appointment %>
<% else %>
placeholder
<% end %>
<% end %>
<% end %>
I think the problem is that @categories.each is looped over every time.
How should we deal with this?
No comments:
Post a Comment