Get first in level in acts_as_nested_set

206 Views Asked by At

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

There are 1 best solutions below

2
On

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.