Search code examples
ruby-on-railstreeviewawesome-nested-set

awesome nested set order by


Im using the awesome nested set plugin for ruby on rails. How do I go about sorting by like :name column or something ?

Currently shows the tree like

A
- C
- B

I want it like

A
- B
- C

Solution

  • Already implemented in awesome_nested_set

    order_column: on which column to do sorting, by default it is the left_column_name. Example: acts_as_nested_set :order_column => :position

    and closure_tree

    If you want a specific order, add a new integer column to your model in a >migration:

    t.integer :sort_order
    

    and in your model:

    class OrderedTag < ActiveRecord::Base
      has_closure_tree order: 'sort_order'
    end