@preComments = Comment.where(:resource_hash => resource_hash).sort(:created_at.desc).all
@preComments.each do |comment|
u = ::User.find_by_id comment.user_id
p u
@comments << @preComments
p "HERE!!!!!"
end
내 코드의
하지만 @comments
은 내가 오류가 그렇게 정의되지 않은 : 내가 먼저 배열을 만들 경우루프를 통해 루프를 반복하면서 nil 객체에 추가하는 방법은 무엇입니까?
You have a nil object when you didn't expect it! You might have expected an instance of Array. The error occurred while evaluating nil.<<
, 그때 내 생각이 그것을 읽을 수 없습니다. 그러면 어떻게해야합니까?
나는 대답했다. 그러나'@ preComments'와'@ comments'를 사용하여 달성하려는 것을 더 잘 설명하면 더 좋은 방법이 될 수있다. –
배열을 처음 만들면보기에서 @comments를 읽을 수없는 이유에 대해 자세히 설명해 주시겠습니까? –