1..5ループでを使用して@comment1
に変更したいと思います。私はかなり反復的な次のコードを持っています。私はそれを乾かしたいと思っています。@comment2
i
こんにちは、acts_as_commentable_with_threadingを使用しています。私は基本的にすべてのコメントをループし、そのコメントに子があるかどうかを確認しています。もしそうなら、それらの子供たちが子供を持っているかどうかを確認しながら子供たちを印刷してください。だから私はいくつかのレベルを深くすることを計画しているので、@ comment1,2,3など...どうすればこれを乾かすことができますか?どうやって再帰?そうでない場合は、たとえば、数レベル深くして、コメントのインデントを@comment5で終了することができます。
編集!
サミロンありがとう!
これが更新されたヘルパー関数です...
def show_comments_with_children(comments)
comments.each do |comment|
yield comment
if comment.children.any?
concat <<-EOF.html_safe
<div class="span7 offset1-1 pcomment">
EOF
show_comments_with_children(comment.children) { |x| yield x } #Dont worry, this will not run another query :)
concat <<-EOF.html_safe
</div>
EOF
end
end
end
<div class="span7 offset1-1 pcomment">
<% @comment1 = comment.children%>
<% for comment in @comment1 %>
<%= render "comment_replies", :comment => comment %>
<div class="span7 offset1-1 pcomment">
<% @comment2 = comment.children%>
<% for comment in @comment2 %>
<%= render "comment_replies", :comment => comment %>
<div class="span7 offset1-1 pcomment">
<% @comment3 = comment.children%>
<% for comment in @comment3 %>
<%= render "comment_replies", :comment => comment %>
<% end %>
</div>
...。
<%(1..5).each do |i| %>
<% @comment1 = comment.children%>
<% for comment in @comment1 %>
<%= render "comment_replies", :comment => comment %>
<% end %>
<% end %>