I am using the ancestry gem with a model called MenuHeader
class MenuHeader < ActiveRecord::Base
has_ancestry
And for example this data model
id name ancestry position
1 MenuHeader#1 NULL 1
2 MenuHeader#2 1 1
3 MenuHeader#3 1/2 2
4 MenuHeader#4 1/2 1
With this representation:
1. MenuHeader#1
2. MenuHeader#2
4. MenuHeader#4 position 1
3. MenuHeader#3 poition 2
Looking at the README at https://github.com/stefankroes/ancestry ; it's not clear how I would achieve this or whether this is possible? I tried putting a scope on it but that didn't seem to work. It seems as if
<% menu_header.children.is_not_deleted.each do |menu_header| %>
<%= render 'menus/ancestry/menu_header_form', menu_header: menu_header %>
<% end %>
would like to be:
<% menu_header.sorted_children.is_not_deleted.each do |menu_header| %>
<%= render 'menus/ancestry/menu_header_form', menu_header: menu_header %>
<% end %>
but not sure how to do do this. Any ideas on how to achieve this?
Edit #1 I have seen this:
Note that since materialised path trees don’t support ordering within a rank, the order of siblings depends on their order in the original array.
in the discussion of sorting but it seems like I should be able to pass a lambda to how this should be sorted.
I use acts_as_list coupled with ancestry to sort my node