codeplant / simple-navigation

A ruby gem for creating navigations (with multiple levels) for your Rails, Sinatra or Padrino applications. Render your navigation as html list, link list or breadcrumbs.
http://simple-navigation-demo.codeplant.ch/
MIT License
885 stars 136 forks source link

Only first level rendered #211

Closed nicolasconnault closed 6 years ago

nicolasconnault commented 6 years ago

I'm running Rails 5 with simple-navigation. I've only slightly adapted the basic configuration file (in config/dashboard_navigation.erb), with one primary item and a secondary item, no conditions. Only the primary item gets rendered.

    SimpleNavigation::Configuration.run do |navigation|
      navigation.items do |primary|
        primary.item :reports, 'Reports', nil do |sub_nav| 
          sub_nav.item :reports_cms, 'CMS Report', reports_stores_path
        end
      end
    end

The code in the view:

<%= render_navigation( context: :dashboard ) %>

And here's the final output:

<ul><li id="reports"><span>Reports</span></li></ul>

Any reason why this is happening?

andi commented 6 years ago

If you set the path of :reports to nil as you do in your config file, the primary item will never know if it is active... you need a path there.

nicolasconnault commented 6 years ago

Weird I thought I'd tried that. So does this mean that it's not possible to have nav items that are just grouping, and don't represent a real URL? For example, I have a bunch of links under "Administration", but there's no main administration page.

andi commented 6 years ago

Well, the default behaviour is to only expose the subnavigation if the parent is active. If there is not chance to determine if the parent is active based on either URL or Regex, simple-navigation can't know if the parent is active. Then your only chance is to use the :expand_all option to always open all levels independent from the active status of parents...