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

2 Answers 2

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
Sign up to request clarification or add additional context in comments.

2 Comments

Thank you soo much. You are a life saver :) I love this platform
Glad to help you. Could you please upvote my answer and accept it as an correct?
0

In Rails 3 instead of using find_all_by use where:

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.