#162 Tree-Based Navigation (revised)
If your Rails app is content-heavy, consider organizing it in a tree menu structure. Here I show how to add top-level tabs, nested links in a side bar, and breadcrumbs to go up the hierarchy.
- Download:
- source code
- mp4
- m4v
- webm
- ogv
Could you post the CSS for the menus? Or add to show notes?
It's in the GitHub repo:
https://github.com/railscasts/162-tree-based-navigation-revised/blob/master/cms-after/app/assets/stylesheets/pages.css.scss
And if you use fragment caching, you should highlight current page in menu using javascript.
Is this true? Is there a way to cache a fragment in the context of the currently viewing page?
Or you can use pure CSS to highlight current page based on nested classes.
E.g, body.products > nav.item
Highlight nav.item.products when the body is also products.
I would also recommend the mongoid-ancestry gem for Mongoid based Rails apps.
I thought
simple_format
might be new... then I found that it was added 8 years ago :PThanks for this episode.
Is there a technical reason for chosing the "Ancestry" gem rather than the "Awesome nested set" gem ? The second one seems to be more popular for few months no ?
I'm afraid that, if I start building my app with Ancestry, it could be deprecated in few weeks. :/
Awesome episode. Is there any way to hide the child and when click on the parents show them? I can use a Javascript for that?
Yes, you could do something like this:
And then open the submenu with, let's say jQuery:
Thank you very much John! that really works.
Thanks, really helpful!
I'm having difficulty finding out how to go about ordering the sub-tree navigation alphabetically?
I see, it's all in the arrange!
https://github.com/stefankroes/ancestry#arrangement
I had a very similar problem. Thank you for posting a solution, this does not happen often on the internet :)
The source code for this episode has been updated to Rails 4.2.6. You can download it from cms4