2011-08-24 2 views
5

코멘트 트리를 보여주고 싶습니다. 나는 다른 관점에서 코멘트 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을 사용합니다. 근본적으로 잘못 되었나요?

+0

@ Draiken의 해결책을 따르거나 부분적으로'comment_'를'single_comment'로 변경하십시오. 이는 변수가 규칙에 따라 명명 된 것과 같습니다. – rubish

답변

8

두 렌더링 라인 모두에 :as => :comment을 추가해야합니다. 렌더링되는 응답에서이 동일한 부분을 다시 렌더링하므로 응답 렌더링도 시도합니다.

설명 및 답변 렌더링 부분에 :as => :comment을 추가하십시오.

+0

감사합니다. 작동합니다! – zishe

+0

답변을 정확하다고 표시하고 평가할 수 있습니까? :) – Draiken

+0

미안하지만, 나는 명성이 충분하지 않습니다. (나는 그것을 벌 수있는 방법을 모른다. 아직 어떤 질문에도 대답 할 수 없다. :) – zishe