Skip to content

Trek::Orderable

Position tracking with acts_as_list, scoped by parent.

What it adds

  • acts_as_list scope: :parent, top_of_list: 0
  • An ordered scope (position order)
  • All the acts_as_list instance methods: insert_at, move_to_top, move_to_bottom, move_higher, move_lower

Requirements

  • A position integer column (and a parent_id column for the scope)

Usage

ruby
class MenuNode < ApplicationRecord
  include Trek::Orderable
end

MenuNode.where(parent: menu).ordered
node.move_to_top

This is what powers drag & drop reordering (SortableJS) in the admin lists.

Released under the MIT License.