0
在此之後SO post,我試圖渲染使用acts_as_tree軌,但沒有成功插件縮進意見。渲染嵌套/線程評論
我認爲問題在於這種方法(我不明白):
def indented_render(num, *args)
render(*args).gsub(/^/, "\t" * num)
end
這是什麼方法替代品?我的部分如下:
%div{:id => "comment_#{comment.id}"}
= comment.body
= render :partial => 'comments/comment', :collection => comment.children
- unless comment.children.empty?
= indented_render 1, :partial => 'comments/comment', :collection => comment.children
但是,沒有一行是縮進的。我究竟做錯了什麼?有沒有更好的方法來呈現評論?
更新:這是生成的html:
<h1>Listing comments</h1>
<table>
<tr>
<td>
<div id='comment_1'>
(152) Facebook version of you: 400 friends. Real version of you: 4 friends
<div id='comment_2'>
(0) Well played.
<div id='comment_3'>
(0) I used to. Then I got married.
<div id='comment_4'>
(17) math is hard
<div id='comment_5'>
(1) What's a math?
<div id='comment_6'>
(1) This made coke come out my nose.
<div id='comment_7'>
(2) So maybe I wasn't the best with fractions.
</div>
<div id='comment_8'>
(1) That sounds terribly painful. Please accept my apologies. Isn't it supposed to be going in your nose, not out?
</div>
</div>
</div>
</div>
</div>
</div>
</div>
不,根本沒有標籤。我附上了我的html的樣子。 – David 2011-05-08 08:31:20
我想我明白了。我有'thread-> comments'(2個不同的模型),我不知道如何以這種方式顯示整個線程歷史記錄,所以我做了一個虛擬根註釋並將它作爲線程註釋的父項('thread-> root_comment-> comments')。有沒有更好的方法來做到這一點? – David 2011-05-09 09:29:21