I am working with a list of categories known as Taxons:
Below is the Rails code snippet:
<div id="taxonomies" class="sidebar-item">
<% @taxonomies.each do |taxonomy| %>
<ul class="navigation-list">
<% taxonomy.root.children.each do |taxon| %>
<li<%= ' class="current"' if @taxon and ([@taxon] + @taxon.ancestors).include?(taxon) %>><%= link_to taxon.name, seo_url(taxon) %></li>
<% if @taxon.nil? %>
<% else %>
<% @taxon.children.each do |taxon|%>
<li><%= link_to taxon.name, seo_url(taxon) %></li>
<% end %>
<% end %>
<% end %>
</ul>
<% end %>
</div>
Currently, I am facing an issue where clicking on a specific taxonomy in the view displays the children of all parents instead of just the selected ones. Here's how it looks right now:
Category 1 Decendent 1 Decendent 2 Category 2 Decendent 1 Decendent 2 Category 3 Decendent 1 Decendent 2
However, what I actually want is:
Category 1 Decendent 1 Decendent 2 Category 2 Category 3
In order to achieve this, I thought about using a conditional statement like <% if :class => 'current %> to only show the LI element if the category has the 'current' class. Does anyone know if this approach is viable?