코멘트 트리를 보여주고 싶습니다. 나는 다른 관점에서 코멘트 DIV를 이동하고, _comments.html.haml
에 다음 줄을 썼다 :레일즈 3에서 컬렉션을 재귀 적 렌더링하기
= render :partial => 'single_comment', :collection => @post.comments.where(:parent_id => nil)
_single_comments.html.haml
:
- if comment.id != nil
.comment
.meta
= comment.name
says
.body
= comment.text
.answers
= render :partial => 'posts/single_comment', :collection => @post.comments.where(:parent_id => comment.id)
그러나 브라우저 나에게 오류가 보여 내가 :as => comment
을 추가하려고
undefined local variable or method `comment' for #<#<Class:0x00000004e39280>:0x00000004e2f398>
Extracted source (around line #1):
1: - if comment.id != nil
2: .comment
3: .meta
4: = comment.name
을 첫 줄에 있지만 작동하지 않습니다. 따라서 부분적으로 @comment
을 사용합니다. 근본적으로 잘못 되었나요?
@ Draiken의 해결책을 따르거나 부분적으로'comment_'를'single_comment'로 변경하십시오. 이는 변수가 규칙에 따라 명명 된 것과 같습니다. – rubish