title: Recursively iterate over nested structure
body: <p>I have nested folder objects like a directory structure on a file system. A user could have:</p>
  
  <ul>
  <li>Folder 1</li>
  <li><p>Folder 2</p>
  
  <ul>
  <li>Folder 2a</li>
  <li>Folder 2b
  <ul>
  <li>Folder 2ba</li>
  <li>Folder 2bb</li>
  </ul></li>
  </ul></li>
  <li><p>Folder 3</p></li>
  </ul>
  
  <p>and so on, as far down as the user wants. I am trying to display the folder structure as in above in a view.</p>
  
  <p>I could do <code>each</code> on the first level, and for each folder in that level, do <code>each</code> on it's children, and then <code>each</code> on it's children and so on, manually. But that seems inefficient. I don't want there to be a pre-set limit to the levels. This seems something that should be automated, but I'm not quite sure how to do so. Furthermore, it seems recursion is not an option because there are no methods in a view.</p>
  
  <p>Is this something a helper would be good for? Should I give up and only load a subfolder when the parent folder is clicked on, using javascript?</p>