title: how to make a Recursive function in rails,that will return all CHILDREN of a parent,and children of all CHILDREN AND SO ON....TO N-LEVELS
body: <p>I have a method as shown:</p>
  
  <pre><code>def all_pages_and_its_n_level_child
  
       @parent_pages = Page.where(:parent_id =&gt; params[:page_id])
       #this will give me all child of this page
       for page in @parent_pages
            child_exists=Page.where(:parent_id=&gt;page.id)
            #this will give all children of that page
            #*I want to make this loop further so that i can check to N-levels,
            #this is only for two levels*
       end
  
  
  end  
  </code></pre>