ruby on rails - Order sub-tree navigation using ancestry gem -


i'm following rails cast tree based navigation.

i want order sub-tree alphabetically.

in pagescontroller have

@page_for_nav = admin::page.find_by_permalink!(params[:id]) 

which gets called by

<%= render 'layouts/sub_navigation', pages: @page_for_nav.root.descendants.arrange %> 

which renders

<ul>   <% pages.each |page, children| %>     <% if page.page_status == 'public' %>     <li>       <%= link_to_unless_current page.name, "../#{page.permalink}" %>       <%= render 'layouts/sub_navigation', pages: children if children.present? %>     </li>     <% end %>   <% end %> </ul>  

doing in pagescontroller fails (no error given, doesn't order)

@page_for_nav = admin::page.order("name asc").find_by_permalink!(params[:id]) 

and doing on each fails (no error given, doesn't order)

<% pages.each.order("name asc") |page, children| %> 

you should pass :order => :name option arrange method

<%= render 'layouts/sub_navigation', pages: @page_for_nav.root.descendants.arrange(:order => :name) %> 

read doc: https://github.com/stefankroes/ancestry#arrangement


Comments

Popular posts from this blog

php - Calling a template part from a post -

Firefox SVG shape not printing when it has stroke -

How to mention the localhost in android -