Search code examples
ruby-on-railsarrayshelpermethods

Return Array in a helper method


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


Solution

  • 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