Solved by fairy in post #5 
              
              
                I solved the problem. It was because I had a method called def children in my model. I changed the method name and the problem solved. Thank you for your help.