문제

Why can't I return an array in a helper method?

def childrenOf(a)
    @children = Post.find_by_parent_id(a.id)        
    return @children 
end

Thanks in advance

도움이 되었습니까?

해결책

You can.

Use find_all_by_parent_id instead.

And you don't need the second line.

The following is enough.

def childrenOf(a)
  @children  = Post.find_all_by_parent_id(a.id)        
end

다른 팁

In Rails 3 instead of using find_all_by use where:

def childrenOf(a)
  @children  = Post.where(:parent_id => a.id)        
end
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top