我有一个评论网站。显示它们时,不应缩进项目的第一次审核,但后续的审核应该是。
HTML输出应该类似于:
<ul>
<li>review for item 1</li>
<li>
review for item 2
<ul>
<li>2nd review for item 2</li>
<li>3rd review for item 2</li>
</ul>
</li>
</ul>
我得到的输出看起来像这样:
<ul>
<li>review for item 1</li>
<li>
review for item 2
</li> <!-- wrong -->
<li> <!-- wrong -->
<ul>
<li>2nd review for item 2</li>
<li>3rd review for item 2</li>
</ul>
</li>
</ul>
_reviews.html.erb
<%= render :partial => "review_item", :collection => @reviews, :locals => { :reviews_local => @reviews } %>
_review_item.html.erb
<% if review_item_counter == 0 %>
<ul>
<% end %>
<li>
<% if @current_reviewable != review_item.id %>
<% @current_reviewable = review_item.id %>
<%= review_item.body %>
<% else %>
<% reviews_local.slice!(review_item_counter, reviews_local.size) %>
<%= render :partial => "review_item", :collection => reviews_local, :locals => { :reviews_local => reviews_local } %>
<% end %>
</li>
<% if review_item_counter == reviews_local.size - 1 %>
</ul>
<% end %>