Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save staycreativedesign/b4d880ffea61d6f4fe14a9a137277fc8 to your computer and use it in GitHub Desktop.
Save staycreativedesign/b4d880ffea61d6f4fe14a9a137277fc8 to your computer and use it in GitHub Desktop.
- Category.all.each do |category|
%li
= link_to(category.title, category_path(category))
- unless category.subcategories.blank?
%ul
- category.subcategories.each do |subcat|
%li
= link_to(subcat.title, category_subcategory_posts_path(category, subcat))
@nilbus
Copy link

nilbus commented Oct 5, 2018

Since you need to have that <ul> there only when there are subcategories, it's hard to avoid.

One idea I had though… you could unconditionally have the <ul> but style it gone when empty:

ul:empty { display: none }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment