Search code examples
ruby-on-railsrubynested-sets

Rails simple navigation, nested set


I built navigation menu using simple navigation and built nested categories which i display in this menu.

navigation.rb code:

  navigation.items do |primary|
    Category.roots.map do |root|
      primary.item ":root_#{root.id}", root.title, category_path(root) do |secondary|
        root.descendants.map do |desc|
          secondary.item ":desc_#{desc.id}", desc.title, category_path(desc)
        end
      end
    end
  end

The question is: how can i display all the levels of categories in my menu. That code does only with two level nesting.

Thank in advance


Solution

  • You will have to use recursive if this helps at all, you can see an example here: Recursive Rails Nested Resources