0

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

Sammy
  • 885
  • 3
  • 13
  • 32

2 Answers2

2

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
Kleber S.
  • 8,110
  • 6
  • 43
  • 69
0

In Rails 3 instead of using find_all_by use where:

def childrenOf(a)
  @children  = Post.where(:parent_id => a.id)        
end
Rahul Tapali
  • 9,887
  • 7
  • 31
  • 44