Reputation: 2198
I am sorry if this question is not appropriate but I am trying to render an unordered list in HAML, HTML version looks like this:
<% @movies.comments.each do |comment| %>
<ul class="comments">
<li><%= comment.text %></li>
</ul>
<% end %>
I used 3 different html->haml online converters and all render this haml.
- @movies.comments.each do |comment|
%ul.comments
%li= comment.text
However the output is this (with 3 comments in a movie):
<ul class="comments">
<li>asdasdasd</li>
</ul>
<ul class="comments">
<li>asdasdasd</li>
</ul>
<ul class="comments">
<li>asdasdasd</li>
</ul>
Why does this create 3 separate ul
elements, instead of one and 3 li
elements in it?
Upvotes: 0
Views: 2555
Reputation: 1890
It's not about HAML. It does what it does because you create ul
element inside loop. What you want to do is to put root ul
node on top:
%ul.comments
- @movies.comments.each do |comment|
%li= comment.text
Upvotes: 4