Skip to content

Use models with `acts_as_tree`

Elyjohn edited this page May 18, 2017 · 4 revisions

How to set up admin for a model with tree behavior ?

Your model needs to include the following pieces of code and you will get a drag-and-droppable index view instead of the classic table view.

class MyTreeModel < ActiveRecord::Base
  acts_as_tree
  class_attribute :max_depth

  scope :ordered, -> { order(position: :asc) }

  def self.max_depth
    # return an integer
  end
end

You can use closure_tree to make your model behave like a tree

Clone this wiki locally