0

I'm using awesome_nested_set in my rails app...in my view I'm displaying my nested categories using each_with_level. How do I determine if the category I'm displaying in the loop is the first in the level.

My list displays like this:

 <ul>
  <li>Gifts
    <ul>
      <li>Kitchen
       <ul>
         <li>Mugs</li>
         <li>Plates</li>
       </ul>
       <li>Bath</li>
       <li>Home
        <ul>
          <li>Canvas Prints</li>
          <li>Framed Prints</li>
        </ul>
      </li>
    </ul>
  </li>
  <li>Blankets
    <ul>
      <li>Fleece</li>
      <li>Cotton</li>
    </ul>
  </li>
</ul>

In this example I would like to tag the "Gifts", "Kitchen", "Mugs", "Canvas Prints", and "Fleece" entries. It seems that there should be a method to determine this, but I couldn't find any documentation on it online. Thanks for any help!

1 Answers1

0

If you don't need the code to know which is first, a CSS selector should be able to do the trick: li:first-child.

dunedain289
  • 2,348
  • 18
  • 21
  • I actually need to get the value by ruby in the loop (each_with_level) – Jodi Buckingham Mar 22 '12 at 19:03
  • I think I figured it out...using the self_and_siblings method I can get the array of all the categories on that level. Then use the .first method for arrays to determine if it's the first in the array. – Jodi Buckingham Mar 22 '12 at 20:45