Sammy
Sammy

Reputation: 963

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

Upvotes: 0

Views: 1019

Answers (2)

Rahul Tapali
Rahul Tapali

Reputation: 10137

In Rails 3 instead of using find_all_by use where:

def childrenOf(a)
  @children  = Post.where(:parent_id => a.id)        
end

Upvotes: 0

Kleber S.
Kleber S.

Reputation: 8240

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

Upvotes: 2

Related Questions