### Usage Example Source: https://github.com/brendon/acts_as_list/blob/master/_autodocs/api-reference/instance-methods.md Example showing how to get the configured `add_new_at` option. ```ruby def add_new_at ``` ``` ```ruby item = TodoItem.find(1) item.add_new_at # => :bottom ``` -------------------------------- ### Model Setup Source: https://github.com/brendon/acts_as_list/blob/master/_autodocs/api-reference/usage-patterns.md Configures a model to add new items to the top of the list by default. ```ruby class StackItem < ApplicationRecord acts_as_list add_new_at: :top end ``` -------------------------------- ### Model Setup with Basic Scope Source: https://github.com/brendon/acts_as_list/blob/master/_autodocs/api-reference/usage-patterns.md Setting up a model to use acts_as_list, scoped by board_id. ```ruby class Card < ApplicationRecord belongs_to :board acts_as_list scope: :board_id end ``` -------------------------------- ### Model Setup Source: https://github.com/brendon/acts_as_list/blob/master/_autodocs/api-reference/usage-patterns.md Sets up the TodoList and Item models, with Item belonging to TodoList and using acts_as_list scoped to the todo_list. ```ruby class TodoList < ApplicationRecord has_many :items, -> { order(position: :asc) }, dependent: :destroy end class Item < ApplicationRecord belongs_to :todo_list acts_as_list scope: :todo_list end ``` -------------------------------- ### Model Setup Source: https://github.com/brendon/acts_as_list/blob/master/_autodocs/api-reference/usage-patterns.md Configures a model to not automatically position new items, requiring manual intervention. ```ruby class DraftItem < ApplicationRecord acts_as_list add_new_at: nil end ``` -------------------------------- ### Model Setup with Composite Foreign Keys Source: https://github.com/brendon/acts_as_list/blob/master/_autodocs/api-reference/usage-patterns.md Configuring acts_as_list for models with composite foreign keys. ```ruby class OrderLine < ApplicationRecord belongs_to :order, foreign_key: [:shop_id, :order_id] acts_as_list scope: [:shop_id, :order_id] end ``` -------------------------------- ### Model Setup Source: https://github.com/brendon/acts_as_list/blob/master/_autodocs/api-reference/usage-patterns.md Integrates acts_as_list with acts_as_paranoid, scoping positions to active (non-deleted) items within a project. ```ruby class Document < ApplicationRecord acts_as_paranoid acts_as_list scope: [:project_id, { deleted_at: nil }] end ``` -------------------------------- ### first? Usage Example Source: https://github.com/brendon/acts_as_list/blob/master/_autodocs/api-reference/instance-methods.md Example demonstrating how to use the first? method. ```ruby list.todo_items.order(position: :asc).each do |item| puts "First!" if item.first? end ``` -------------------------------- ### Model Setup with Conditional Scopes Source: https://github.com/brendon/acts_as_list/blob/master/_autodocs/api-reference/usage-patterns.md Using acts_as_list with a scope based on a plain text field. ```ruby class TaskItem < ApplicationRecord # Scope by plain text field, not association acts_as_list scope: [:category] end ``` -------------------------------- ### Installation Source: https://github.com/brendon/acts_as_list/blob/master/README.md Instructions for installing the acts_as_list gem. ```ruby gem 'acts_as_list' ``` ```bash gem install acts_as_list ``` -------------------------------- ### Model Setup Source: https://github.com/brendon/acts_as_list/blob/master/_autodocs/api-reference/usage-patterns.md Configures OrderItem to use acts_as_list with multiple scope attributes: order_id and category_id, creating independent position sequences for each combination. ```ruby class OrderItem < ApplicationRecord belongs_to :order belongs_to :category acts_as_list scope: [:order_id, :category_id] end ``` -------------------------------- ### Usage Example for acts_as_list_options Source: https://github.com/brendon/acts_as_list/blob/master/_autodocs/api-reference/acts-as-list.md Example demonstrating how to retrieve the configuration options used by acts_as_list. ```ruby class TodoItem < ActiveRecord::Base acts_as_list scope: :todo_list, column: :position end TodoItem.acts_as_list_options # => { column: "position", scope: :todo_list_id, top_of_list: 1, add_new_at: :bottom, touch_on_update: true } ``` -------------------------------- ### Usage Example Source: https://github.com/brendon/acts_as_list/blob/master/_autodocs/api-reference/instance-methods.md Example demonstrating how to use acts_as_list with a scope. ```ruby class TodoItem < ActiveRecord::Base acts_as_list scope: :todo_list end item = TodoItem.find(1) item.scope_name # => :todo_list_id ``` -------------------------------- ### Usage Example Source: https://github.com/brendon/acts_as_list/blob/master/_autodocs/api-reference/instance-methods.md Example showing how to get the class on which acts_as_list is defined. ```ruby def acts_as_list_class ``` ``` ```ruby item = TodoItem.find(1) item.acts_as_list_class # => TodoItem ``` -------------------------------- ### Usage Example Source: https://github.com/brendon/acts_as_list/blob/master/_autodocs/api-reference/instance-methods.md Example demonstrating how to retrieve the configured top position value. ```ruby def acts_as_list_top ``` ``` ```ruby item = TodoItem.find(1) item.acts_as_list_top # => 1 ``` -------------------------------- ### Usage Example for acts_as_list_top Source: https://github.com/brendon/acts_as_list/blob/master/_autodocs/api-reference/class-methods.md Example of how to use the acts_as_list_top method, including configuration. ```ruby class TodoItem < ActiveRecord::Base acts_as_list top_of_list: 0 end TodoItem.acts_as_list_top # => 0 ``` -------------------------------- ### current_position Usage Example Source: https://github.com/brendon/acts_as_list/blob/master/_autodocs/api-reference/instance-methods.md Example demonstrating how to use the current_position method. ```ruby item = TodoItem.find(1) item.current_position # => 3 ``` -------------------------------- ### set_list_position Usage Example Source: https://github.com/brendon/acts_as_list/blob/master/_autodocs/api-reference/instance-methods.md Example demonstrating how to use the set_list_position method. ```ruby item = TodoItem.find(1) item.set_list_position(10) item.current_position # => 10 item.set_list_position(nil) item.in_list? # => false ``` -------------------------------- ### Scope Configuration: String (Raw SQL) - Advanced Examples Source: https://github.com/brendon/acts_as_list/blob/master/_autodocs/configuration.md Advanced examples of using raw SQL strings for time-based and custom logic scopes. ```ruby # Time-based scope acts_as_list scope: "user_id = #{user_id} AND created_month = '#{created_at.strftime('%Y-%m')}'" # Custom logic scope acts_as_list scope: "project_id = #{project_id} AND status != 'archived'" ``` -------------------------------- ### Usage Example for quoted_position_column_with_table_name Source: https://github.com/brendon/acts_as_list/blob/master/_autodocs/api-reference/class-methods.md Example of how to use the quoted_position_column_with_table_name method. ```ruby TodoItem.quoted_position_column_with_table_name # => "todo_items"."position" ``` -------------------------------- ### Usage Example for quoted_position_column Source: https://github.com/brendon/acts_as_list/blob/master/_autodocs/api-reference/class-methods.md Example of how to use the quoted_position_column method. ```ruby TodoItem.quoted_position_column # => "position" (with quotes appropriate for the database) ``` -------------------------------- ### in_list? Usage Example Source: https://github.com/brendon/acts_as_list/blob/master/_autodocs/api-reference/instance-methods.md Example demonstrating how to use the in_list? method. ```ruby item = TodoItem.find(1) item.in_list? # => true item.remove_from_list item.in_list? # => false ``` -------------------------------- ### move_to_top Usage Example Source: https://github.com/brendon/acts_as_list/blob/master/_autodocs/api-reference/instance-methods.md Example demonstrating how to use the move_to_top method to move an item to the beginning of the list. ```ruby item = TodoItem.find(3) item.current_position # => 3 item.move_to_top item.current_position # => 1 ``` -------------------------------- ### Model Setup: Disabling Timestamp Updates Source: https://github.com/brendon/acts_as_list/blob/master/_autodocs/api-reference/usage-patterns.md Configuring acts_as_list to not update timestamps on position changes. ```ruby class MenuItem < ApplicationRecord acts_as_list scope: :menu_id, touch_on_update: false end ``` -------------------------------- ### Usage Example Source: https://github.com/brendon/acts_as_list/blob/master/_autodocs/api-reference/instance-methods.md Example demonstrating how to test if acts_as_list updates are disabled. ```ruby def act_as_list_no_update? ``` ``` ```ruby item = TodoItem.find(1) item.act_as_list_no_update? # => false TodoItem.acts_as_list_no_update do item.act_as_list_no_update? # => true end ``` -------------------------------- ### increment_position Usage Example Source: https://github.com/brendon/acts_as_list/blob/master/_autodocs/api-reference/instance-methods.md Example demonstrating how to use the increment_position method. ```ruby item = TodoItem.find(1) item.current_position # => 5 item.increment_position item.current_position # => 6 ``` -------------------------------- ### insert_at Usage Example Source: https://github.com/brendon/acts_as_list/blob/master/_autodocs/api-reference/instance-methods.md Example demonstrating how to use the insert_at method to place an item at a specific position. ```ruby item = TodoItem.find(1) item.insert_at(3) item.current_position # => 3 # All items that were at positions 3+ are shifted down ``` -------------------------------- ### lower_item Usage Example Source: https://github.com/brendon/acts_as_list/blob/master/_autodocs/api-reference/instance-methods.md Example showing how to retrieve the next lower item in the list. ```ruby item = TodoItem.find(2) next_item = item.lower_item # Item at position 3 next_item.current_position # => 3 ``` -------------------------------- ### insert_at! Usage Example Source: https://github.com/brendon/acts_as_list/blob/master/_autodocs/api-reference/instance-methods.md Example demonstrating how to use the insert_at! method, which raises an exception if the save fails. ```ruby item = TodoItem.find(1) item.insert_at!(5) # Raises if save fails ``` -------------------------------- ### lower_items Usage Example Source: https://github.com/brendon/acts_as_list/blob/master/_autodocs/api-reference/instance-methods.md Examples demonstrating how to retrieve multiple lower items, with and without a limit. ```ruby item = TodoItem.find(2) item.lower_items # Items at positions 3, 4, 5 (ordered 3, 4, 5) item.lower_items(1) # Item at position 3 (the closest) item.lower_items(2) # Items at positions 3, 4 ``` -------------------------------- ### Configuration Examples Source: https://github.com/brendon/acts_as_list/blob/master/_autodocs/README.md Demonstrates various configuration options for acts_as_list, including scoping, item placement, indexing, and custom columns. ```ruby # Multiple lists per table (most common) acts_as_list scope: :parent_id # Add new items at top instead of bottom acts_as_list add_new_at: :top # Zero-based indexing (like arrays) acts_as_list top_of_list: 0 # Multiple scope columns with fixed constraints acts_as_list scope: [:list_id, { active: true }] # Custom position column acts_as_list column: :order # Disable timestamp updates on position changes acts_as_list touch_on_update: false ``` -------------------------------- ### Array-like indexing starting at 0 Source: https://github.com/brendon/acts_as_list/blob/master/_autodocs/api-reference/acts-as-list.md Example of configuring acts_as_list to use 0-based indexing for positions. ```ruby class MenuItem < ActiveRecord::Base belongs_to :menu acts_as_list scope: :menu, top_of_list: 0 end item = MenuItem.first item.current_position # => 0 (instead of 1) ``` -------------------------------- ### higher_item Usage Example Source: https://github.com/brendon/acts_as_list/blob/master/_autodocs/api-reference/instance-methods.md Example showing how to retrieve the next higher item in the list. ```ruby item = TodoItem.find(3) prev_item = item.higher_item # Item at position 2 prev_item.current_position # => 2 ``` -------------------------------- ### Basic Usage Example Source: https://github.com/brendon/acts_as_list/blob/master/README.md Example demonstrating how to add a position column, migrate the database, and use acts_as_list in a Rails model. ```ruby rails g migration AddPositionToTodoItem position:integer rake db:migrate ``` ```ruby class TodoList < ActiveRecord::Base has_many :todo_items, -> { order(position: :asc) } end class TodoItem < ActiveRecord::Base belongs_to :todo_list acts_as_list scope: :todo_list end todo_list = TodoList.find(...) todo_list.todo_items.first.move_to_bottom todo_list.todo_items.last.move_higher ``` -------------------------------- ### decrement_position Usage Example Source: https://github.com/brendon/acts_as_list/blob/master/_autodocs/api-reference/instance-methods.md Example demonstrating how to use the decrement_position method. ```ruby item = TodoItem.find(5) item.current_position # => 5 item.decrement_position item.current_position # => 4 ``` -------------------------------- ### move_within_scope Usage Example Source: https://github.com/brendon/acts_as_list/blob/master/_autodocs/api-reference/instance-methods.md Example demonstrating how to use the move_within_scope method. ```ruby item = TodoItem.find(1) item.todo_list_id # => 1 item.move_within_scope(2) item.todo_list_id # => 2 item.current_position # => Reassigned in new list ``` -------------------------------- ### higher_items Usage Example Source: https://github.com/brendon/acts_as_list/blob/master/_autodocs/api-reference/instance-methods.md Examples demonstrating how to retrieve multiple higher items, with and without a limit. ```ruby item = TodoItem.find(4) item.higher_items # Items at positions 1, 2, 3 (ordered 3, 2, 1) item.higher_items(1) # Item at position 3 (the closest) item.higher_items(2) # Items at positions 3, 2 ``` -------------------------------- ### increment_all Usage Example Source: https://github.com/brendon/acts_as_list/blob/master/_autodocs/api-reference/class-methods.md Example of how to use the `increment_all` method to increase positions. ```ruby TodoItem.increment_all # All items' positions increased by 1 ``` -------------------------------- ### Bulk Import with Position Control Source: https://github.com/brendon/acts_as_list/blob/master/_autodocs/api-reference/usage-patterns.md Demonstrates how to import multiple items efficiently while preserving their specified positions using `acts_as_list_no_update`. ```ruby class ImportedItem < ApplicationRecord acts_as_list scope: :import_batch end ``` ```ruby def import_items(batch_id, csv_data) ImportedItem.acts_as_list_no_update do csv_data.each.with_index(1) do |row, position| ImportedItem.create( import_batch_id: batch_id, title: row[:title], position: position ) end end end ``` -------------------------------- ### not_in_list? Usage Example Source: https://github.com/brendon/acts_as_list/blob/master/_autodocs/api-reference/instance-methods.md Example demonstrating how to use the not_in_list? method. ```ruby item = TodoItem.new item.not_in_list? # => true item.save item.not_in_list? # => false ``` -------------------------------- ### Usage Source: https://github.com/brendon/acts_as_list/blob/master/_autodocs/api-reference/usage-patterns.md Demonstrates how items are positioned independently within their respective order and category combinations. ```ruby order = Order.create cat1 = Category.create(name: "Electronics") cat2 = Category.create(name: "Books") # Each order+category combo has separate positions item1 = order.items.create(category: cat1, product: "Laptop") # position: 1 item2 = order.items.create(category: cat1, product: "Mouse") # position: 2 item3 = order.items.create(category: cat2, product: "Rails") # position: 1 item4 = order.items.create(category: cat2, product: "Ruby") # position: 2 ``` -------------------------------- ### Simple List Configuration Source: https://github.com/brendon/acts_as_list/blob/master/_autodocs/configuration.md Example of a basic `acts_as_list` configuration where all items in a table share a single position sequence. ```ruby class MenuItem < ActiveRecord::Base acts_as_list end # Position: 1, 2, 3, 4... # All items share one sequence ``` -------------------------------- ### move_lower Usage Example Source: https://github.com/brendon/acts_as_list/blob/master/_autodocs/api-reference/instance-methods.md Example demonstrating how to use the move_lower method to change an item's position. ```ruby @items = TodoItem.all.order(position: :asc) @items.first.current_position # => 1 @items.first.move_lower @items.first.current_position # => 2 ``` -------------------------------- ### Usage: Composite Foreign Keys Source: https://github.com/brendon/acts_as_list/blob/master/_autodocs/api-reference/usage-patterns.md Demonstrates correct positioning and movement with composite foreign keys. ```ruby line1 = OrderLine.create(shop_id: 1, order_id: 10, product: "Widget") line2 = OrderLine.create(shop_id: 1, order_id: 10, product: "Gadget") line1.current_position # 1 line2.current_position # 2 # Scoping works correctly with composite keys line1.move_lower line1.current_position # 2 ``` -------------------------------- ### default_position? Usage Example Source: https://github.com/brendon/acts_as_list/blob/master/_autodocs/api-reference/instance-methods.md Example demonstrating the usage of the default_position? method to check if an item is at its default position. ```ruby item = TodoItem.new # Gets default position item.default_position? # => true item.insert_at(5) item.default_position? # => false ``` -------------------------------- ### Usage Example Source: https://github.com/brendon/acts_as_list/blob/master/_autodocs/api-reference/instance-methods.md An example demonstrating how to iterate through ordered list items and check if an item is the last one. ```ruby list.todo_items.order(position: :asc).each do |item| puts "Last!" if item.last? end ``` -------------------------------- ### position_column Usage Example Source: https://github.com/brendon/acts_as_list/blob/master/_autodocs/api-reference/instance-methods.md Example showing how to retrieve the name of the position column for a model. ```ruby item = TodoItem.find(1) item.position_column # => "position" ``` -------------------------------- ### move_higher Usage Example Source: https://github.com/brendon/acts_as_list/blob/master/_autodocs/api-reference/instance-methods.md Example demonstrating how to use the move_higher method to change an item's position. ```ruby @items = TodoItem.all.order(position: :asc) @items.last.current_position # => 5 @items.last.move_higher @items.last.current_position # => 4 ``` -------------------------------- ### default_position Usage Example Source: https://github.com/brendon/acts_as_list/blob/master/_autodocs/api-reference/instance-methods.md Example showing how to retrieve the default position value for a model and an instance. ```ruby TodoItem.column_defaults['position'] # => 1 item = TodoItem.new item.default_position # => 1 ``` -------------------------------- ### Position Shuffling Algorithm Example Source: https://github.com/brendon/acts_as_list/blob/master/_autodocs/architecture.md Illustrates the position shuffling logic when an item is moved between positions, showing the before, temporary, and final states. ```text If moving from position 2 to position 5: Before: [1, 2*, 3, 4, 5, 6] (* item being moved) Temp: [1, 2*, 3, 4, 5, 99] Step 1: Decrement [3, 4, 5] → [2, 3, 4] Final: [1, 3, 4, 5, 2*, 6] Then set position to 5: [1, 3, 4, 5, 2*, 6] ``` -------------------------------- ### move_to_bottom Usage Example Source: https://github.com/brendon/acts_as_list/blob/master/_autodocs/api-reference/instance-methods.md Example demonstrating how to use the move_to_bottom method to move an item to the end of the list. ```ruby item = TodoItem.find(1) item.current_position # => 2 item.move_to_bottom item.current_position # => 5 (was last, now is at bottom) ``` -------------------------------- ### Scope Configuration: String (Raw SQL) Source: https://github.com/brendon/acts_as_list/blob/master/_autodocs/configuration.md Example of using a raw SQL string for advanced scope control with interpolation. ```ruby class TodoItem < ActiveRecord::Base belongs_to :list acts_as_list scope: "list_id = #{list_id} AND completed = 0" end # Interpolation happens at runtime with the item's attribute values ``` -------------------------------- ### Usage Source: https://github.com/brendon/acts_as_list/blob/master/_autodocs/api-reference/usage-patterns.md Shows how new items are automatically added to the top, shifting existing items down. ```ruby StackItem.create(title: "Item A") # position: 1 StackItem.create(title: "Item B") # position: 1 (Item A moved to 2) StackItem.create(title: "Item C") # position: 1 (Item B moved to 2, Item A to 3) StackItem.order(position: :asc) # [C, B, A] ``` -------------------------------- ### Usage: Moving Cards Between Boards Source: https://github.com/brendon/acts_as_list/blob/master/_autodocs/api-reference/usage-patterns.md Demonstrates creating cards, checking their position, and moving a card to a different board. ```ruby board1 = Board.create(name: "Todo") board2 = Board.create(name: "Done") card = board1.cards.create(title: "Task") card.current_position # 1 (in board1) # Move to different board card.move_within_scope(board2.id) card.board_id # board2.id card.current_position # 1 (positions reset in new board) # Equivalent manual approach card.board_id = board2.id card.save! # Card is automatically positioned at bottom of board2 ``` -------------------------------- ### JavaScript/AJAX for Drag-and-Drop Source: https://github.com/brendon/acts_as_list/blob/master/_autodocs/api-reference/usage-patterns.md Example JavaScript code using the Fetch API to send a PATCH request to a Rails backend for reordering an item. ```javascript function moveItem(itemId, newPosition) { fetch(`/items/${itemId}/reorder`, { method: 'PATCH', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ position: newPosition }) }) .then(r => r.json()) .then(data => { if (data.error) { alert('Reorder failed: ' + data.error); } else { refreshList(); } }); } ``` -------------------------------- ### Manual Positioning Configuration Source: https://github.com/brendon/acts_as_list/blob/master/_autodocs/configuration.md Example of configuring `acts_as_list` for manual positioning, where new items are created with a nil position. ```ruby class CustomItem < ActiveRecord::Base acts_as_list add_new_at: nil end # New items created with position = nil # Must be explicitly positioned using insert_at, move_to_top, etc. ``` -------------------------------- ### Scope Configuration: Array (Column Names) Source: https://github.com/brendon/acts_as_list/blob/master/_autodocs/configuration.md Example of using an array of column names for scope, grouping items by multiple criteria. ```ruby class TodoItem < ActiveRecord::Base belongs_to :list acts_as_list scope: [:list_id, :user_id] end # Items are grouped by list_id AND user_id ``` -------------------------------- ### remove_from_list Usage Example Source: https://github.com/brendon/acts_as_list/blob/master/_autodocs/api-reference/instance-methods.md Example demonstrating how to use the remove_from_list method to remove an item from its list. ```ruby item = TodoItem.find(2) item.current_position # => 2 item.remove_from_list item.current_position # => nil item.in_list? # => false ``` -------------------------------- ### Usage: Conditional Scopes Source: https://github.com/brendon/acts_as_list/blob/master/_autodocs/api-reference/usage-patterns.md Demonstrates how items are positioned independently within different categories. ```ruby # Each category has separate positions work_task1 = TaskItem.create(category: "work", title: "Email") # position: 1 work_task2 = TaskItem.create(category: "work", title: "Meeting") # position: 2 home_task1 = TaskItem.create(category: "home", title: "Laundry") # position: 1 home_task2 = TaskItem.create(category: "home", title: "Dishes") # position: 2 # Changing category moves it to the new scope work_task1.category = "home" work_task1.save! # work_task1 is now in "home" scope at bottom position ``` -------------------------------- ### String Scope Example Source: https://github.com/brendon/acts_as_list/blob/master/_autodocs/architecture.md Illustrates the use of a string scope, which is interpolated with item attributes at runtime. ```ruby acts_as_list scope: "list_id = #{list_id} AND completed = 0" ``` -------------------------------- ### Scope Configuration: Symbol Source: https://github.com/brendon/acts_as_list/blob/master/_autodocs/configuration.md Example of using a symbol for scope, automatically converted to a foreign key. ```ruby class TodoItem < ActiveRecord::Base belongs_to :todo_list acts_as_list scope: :todo_list end # Converted internally to scope: :todo_list_id # Each list maintains separate positions for its items ``` -------------------------------- ### Add Items at Top Configuration Source: https://github.com/brendon/acts_as_list/blob/master/_autodocs/configuration.md Example of configuring `acts_as_list` to add new items to the top of the list by default. ```ruby class Priority < ActiveRecord::Base belongs_to :project acts_as_list scope: :project, add_new_at: :top end # New items always added at position 1 # Existing items shifted down ``` -------------------------------- ### Unscoped Queries Example Source: https://github.com/brendon/acts_as_list/blob/master/_autodocs/architecture.md Demonstrates how `.unscoped` is used to bypass default scopes when querying for `acts_as_list` items. ```ruby acts_as_list_list = acts_as_list_class.default_scoped.unscope(:select, :where).where(scope_condition) ``` -------------------------------- ### Scope Configuration: Array with Fixed Constraints Source: https://github.com/brendon/acts_as_list/blob/master/_autodocs/configuration.md Example of using an array with a hash for fixed constraints in scope. ```ruby class TodoItem < ActiveRecord::Base belongs_to :list acts_as_list scope: [:list_id, { active: true }] end # Items are grouped by list_id AND must have active = true ``` -------------------------------- ### Zero-Based Indexing Source: https://github.com/brendon/acts_as_list/blob/master/_autodocs/api-reference/usage-patterns.md Shows how to configure acts_as_list to use zero-based indexing for positions, useful when integrating with array-like structures. ```ruby class Slide < ApplicationRecord belongs_to :presentation acts_as_list scope: :presentation, top_of_list: 0 end ``` ```ruby presentation = Presentation.create slide1 = presentation.slides.create # position: 0 slide2 = presentation.slides.create # position: 1 slide3 = presentation.slides.create # position: 2 slide1.current_position # 0 (not 1) slide3.current_position # 2 (not 3) slide1.move_to_bottom slide1.current_position # 2 ``` -------------------------------- ### Behavior: Position Gaps and Disparate Values Source: https://github.com/brendon/acts_as_list/blob/master/_autodocs/api-reference/usage-patterns.md Demonstrates how acts_as_list handles non-sequential position values and preserves gaps during movement. ```ruby list = List.create item1 = list.items.create(position: 10) # Allowed item2 = list.items.create(position: 20) # Allowed (gap exists) item3 = list.items.create(position: 30) # higher_items and lower_items work correctly with gaps item2.higher_items # [item1] item2.lower_items # [item3] # Movement preserves gap structure item1.move_to_bottom # item1 is now at position 30 (inserted at bottom, gap maintained) ``` -------------------------------- ### in_list Scope Usage Example Source: https://github.com/brendon/acts_as_list/blob/master/_autodocs/api-reference/class-methods.md Example of how to use the `in_list` scope to retrieve items that are part of the list. ```ruby # Get only items that are currently in the list items_in_list = TodoItem.in_list # Chain with other scopes active_items = TodoItem.in_list.where(active: true).order(position: :asc) ``` -------------------------------- ### current_position Source: https://github.com/brendon/acts_as_list/blob/master/_autodocs/api-reference/instance-methods.md Gets the current position of the item in the list. ```ruby def current_position ``` -------------------------------- ### Symbol Scope Example Source: https://github.com/brendon/acts_as_list/blob/master/_autodocs/architecture.md Demonstrates how a symbol scope is defined and converted into a hash condition for database queries. ```ruby acts_as_list scope: :todo_list # Converted to :todo_list_id ``` ```ruby { todo_list_id: self.todo_list_id } ``` -------------------------------- ### Drag-and-Drop Controller Source: https://github.com/brendon/acts_as_list/blob/master/_autodocs/README.md Example controller action for handling drag-and-drop reordering of list items. ```ruby def reorder item = Item.find(params[:id]) item.insert_at(params[:position].to_i) render json: item end ``` -------------------------------- ### Custom Column Name Source: https://github.com/brendon/acts_as_list/blob/master/_autodocs/api-reference/usage-patterns.md Illustrates how to use a column other than the default 'position' to store list order. ```ruby class MenuItem < ApplicationRecord acts_as_list column: :order end ``` ```ruby class CreateMenuItems < ActiveRecord::Migration[6.0] def change create_table :menu_items do |t| t.string :label t.integer :order # Custom column name t.timestamps end add_index :menu_items, :order, unique: true end end ``` ```ruby item1 = MenuItem.create(label: "Home") # order: 1 item2 = MenuItem.create(label: "About") # order: 2 item1.move_lower item1.order # 2 (instead of position) ``` -------------------------------- ### How to Catch and Retry ActiveRecord::Deadlocked Source: https://github.com/brendon/acts_as_list/blob/master/_autodocs/errors.md Example demonstrating how to catch and retry a database deadlock. ```ruby max_retries = 3 attempts = 0 begin TodoItem.transaction do item.insert_at(5) end rescue ActiveRecord::Deadlocked attempts += 1 if attempts < max_retries sleep(0.1) # Brief wait before retry retry else raise end end ``` -------------------------------- ### Zero-Based Indexing Configuration Source: https://github.com/brendon/acts_as_list/blob/master/_autodocs/configuration.md Example of configuring `acts_as_list` to use zero-based indexing for positions, similar to array indexing. ```ruby class Slide < ActiveRecord::Base acts_as_list top_of_list: 0 end # Position: 0, 1, 2, 3... # Matches array indexing behavior ``` -------------------------------- ### Array Scope Example Source: https://github.com/brendon/acts_as_list/blob/master/_autodocs/architecture.md Shows how an array scope, including fixed constraints, is converted into a merged hash condition. ```ruby acts_as_list scope: [:list_id, :user_id, { active: true }] ``` ```ruby { list_id: self.list_id, user_id: self.user_id, active: true } ``` -------------------------------- ### Multiple Scopes Configuration Source: https://github.com/brendon/acts_as_list/blob/master/_autodocs/configuration.md Example of `acts_as_list` configured with multiple scope columns, creating independent position sequences for combinations of these scopes. ```ruby class OrderItem < ActiveRecord::Base belongs_to :order belongs_to :category acts_as_list scope: [:order_id, :category_id] end # Each order has separate position sequences per category # order_id=1, category_id=1 has items at positions 1, 2, 3 # order_id=1, category_id=2 has items at positions 1, 2, 3 (separate) ``` -------------------------------- ### Catching Specific Errors Source: https://github.com/brendon/acts_as_list/blob/master/_autodocs/api-reference/class-methods.md Example of how to catch specific errors thrown by `acts_as_list_no_update`. ```ruby begin TodoItem.acts_as_list_no_update("not_array") do # ... end rescue ActiveRecord::Acts::List::NoUpdate::ArrayTypeError => e puts "Expected Array, got String" end ``` -------------------------------- ### Soft-Delete Pattern Configuration Source: https://github.com/brendon/acts_as_list/blob/master/_autodocs/configuration.md Example of integrating `acts_as_list` with a soft-delete pattern, ensuring only non-deleted items are part of the list. ```ruby class TodoItem < ActiveRecord::Base acts_as_paranoid acts_as_list scope: [:todo_list_id, { deleted_at: nil }] end # Only non-deleted items are included in the list # Deleted items don't participate in position management ``` -------------------------------- ### Multiple scopes with fixed parameters Source: https://github.com/brendon/acts_as_list/blob/master/_autodocs/api-reference/acts-as-list.md Example showing how to define multiple scopes for ordering, including fixed parameters. ```ruby class TodoItem < ActiveRecord::Base belongs_to :list acts_as_list scope: [:list_id, { active: true }] end # Only positions items where active = true within a specific list ``` -------------------------------- ### Bulk Import Source: https://github.com/brendon/acts_as_list/blob/master/_autodocs/README.md Example of performing a bulk import of items while disabling acts_as_list updates. ```ruby TodoItem.acts_as_list_no_update do csv_data.each.with_index(1) do |row, position| TodoItem.create(row.merge(position: position)) end end ``` -------------------------------- ### Scoped List Configuration Source: https://github.com/brendon/acts_as_list/blob/master/_autodocs/configuration.md Example of `acts_as_list` configured with a scope, creating separate position sequences for items within different lists. ```ruby class TodoItem < ActiveRecord::Base belongs_to :todo_list acts_as_list scope: :todo_list end # Each todo_list has its own position sequence # item1 in list1: position 1 # item1 in list2: position 1 (separate from list1) ``` -------------------------------- ### Database Schema for Conditional Scopes Source: https://github.com/brendon/acts_as_list/blob/master/_autodocs/api-reference/usage-patterns.md Schema definition for TaskItems, including a category field for scoping. ```ruby class CreateTaskItems < ActiveRecord::Migration[6.0] def change create_table :task_items do |t| t.string :title t.string :category # Plain text field, not foreign key t.integer :position t.timestamps end add_index :task_items, [:category, :position], unique: true end end ``` -------------------------------- ### Database Connection Abstraction - WithConnection Helper Source: https://github.com/brendon/acts_as_list/blob/master/_autodocs/architecture.md Example of using the `WithConnection` helper to safely obtain and use database connections for operations like quoting column names or checking index existence. ```ruby ActiveRecord::Acts::List::WithConnection.new(model_class).call do |connection| connection.quote_column_name(position_column) connection.index_exists?(table_name, column, unique: true) end ``` -------------------------------- ### Usage Source: https://github.com/brendon/acts_as_list/blob/master/_autodocs/api-reference/usage-patterns.md Demonstrates that new items are not positioned by default and require explicit methods like insert_at or remove_from_list to manage their list status. ```ruby # New items are not positioned item = DraftItem.create(title: "Draft") item.in_list? # false item.current_position # nil # Explicitly add to list item.move_to_bottom # Error: item not in list, returns nil item.insert_at(1) # Item enters list at position 1 item.in_list? # true # Remove from list item.remove_from_list item.in_list? # false ``` -------------------------------- ### Default Scope Behavior Source: https://github.com/brendon/acts_as_list/blob/master/_autodocs/api-reference/usage-patterns.md Demonstrates that items in different scopes maintain their relative order even if they have the same position number. ```ruby item1.current_position # 1 item3.current_position # 1 item1.move_lower # position: 2 item1.current_position # 2 item3.current_position # Still 1 (different scope) ``` -------------------------------- ### Multiple scopes configuration Source: https://github.com/brendon/acts_as_list/blob/master/README.md Example of configuring acts_as_list with multiple scopes, including an association ID and a text field. ```ruby class TodoItem < ActiveRecord::Base belongs_to :todo_list acts_as_list scope: [:task_category, :todo_list_id] end ``` -------------------------------- ### Custom Column Name Configuration Source: https://github.com/brendon/acts_as_list/blob/master/_autodocs/configuration.md Example of configuring `acts_as_list` to use a custom column name for storing the position. ```ruby class Layout < ActiveRecord::Base acts_as_list column: :order end # Uses 'order' column instead of 'position' # layout.order instead of layout.position ``` -------------------------------- ### Database Schema for Composite Foreign Keys Source: https://github.com/brendon/acts_as_list/blob/master/_autodocs/api-reference/usage-patterns.md Schema definition supporting composite foreign keys for OrderLines. ```ruby class CreateOrderLines < ActiveRecord::Migration[6.0] def change create_table :order_lines do |t| t.bigint :shop_id t.bigint :order_id t.string :product t.integer :position t.timestamps end add_foreign_key :order_lines, :orders, column: [:shop_id, :order_id] add_index :order_lines, [:shop_id, :order_id, :position], unique: true end end ``` -------------------------------- ### Custom column name Source: https://github.com/brendon/acts_as_list/blob/master/_autodocs/api-reference/acts-as-list.md Example demonstrating how to specify a custom column name for storing the position. ```ruby class Slide < ActiveRecord::Base belongs_to :presentation acts_as_list column: :order, scope: :presentation end slide = Slide.find(1) slide.order # => 1 (instead of slide.position) ``` -------------------------------- ### Bulk data import with manual position management Source: https://github.com/brendon/acts_as_list/blob/master/_autodocs/api-reference/class-methods.md Example for performing bulk data imports efficiently by disabling acts_as_list callbacks. ```ruby # When importing many items, disable callbacks for performance TodoItem.acts_as_list_no_update do large_dataset.each do |row| TodoItem.create( todo_list: todo_list, description: row[:description], position: row[:position] ) end end # Positions are preserved as provided in the dataset # Callbacks are not triggered, improving performance ``` -------------------------------- ### Unique Index Behavior Source: https://github.com/brendon/acts_as_list/blob/master/_autodocs/configuration.md Examples of adding unique indexes to the position column, including scope columns and deferrable constraints for PostgreSQL. ```ruby # For scope: :todo_list add_index :todo_items, [:todo_list_id, :position], unique: true # For scope: [:list_id, :user_id] add_index :todo_items, [:list_id, :user_id, :position], unique: true # PostgreSQL deferrable constraint add_index :items, [:list_id, :position], unique: true, deferrable: :deferred, using: :btree ``` -------------------------------- ### Usage Source: https://github.com/brendon/acts_as_list/blob/master/_autodocs/api-reference/usage-patterns.md Illustrates how deleting an item removes it from the active list's sequence, while still being retrievable with `with_deleted` and restorable. ```ruby project = Project.create(name: "Docs") doc1 = project.documents.create(title: "Doc 1") # position: 1 doc2 = project.documents.create(title: "Doc 2") # position: 2 doc3 = project.documents.create(title: "Doc 3") # position: 3 # Delete doc1 doc1.destroy # Only active documents have positions project.documents.in_list # [doc2, doc3] with positions [1, 2] Document.with_deleted.in_list.count # 3 (includes deleted) # Restore doc1 doc1.restore project.documents.in_list.count # 3 ``` -------------------------------- ### Concise API for creating list items Source: https://github.com/brendon/acts_as_list/blob/master/README.md Example demonstrating a more concise API for creating a list item at a specific position, which results in fewer SQL statements and faster transactions. ```ruby # Good TodoItem.create(todo_list: todo_list, position: 1) # Bad item = TodoItem.create(todo_list: todo_list) item.insert_at(1) ``` -------------------------------- ### Usage Source: https://github.com/brendon/acts_as_list/blob/master/_autodocs/api-reference/usage-patterns.md Demonstrates creating items, reordering them using methods like move_lower, move_to_top, insert_at, and querying relationships like higher_items and lower_items. ```ruby list = TodoList.create(name: "My List") # Create items - they are automatically positioned item1 = list.items.create(description: "Task 1") # position: 1 item2 = list.items.create(description: "Task 2") # position: 2 item3 = list.items.create(description: "Task 3") # position: 3 # Reorder items item1.move_lower # Now: item2 at 1, item1 at 2, item3 at 3 item3.move_to_top # Now: item3 at 1, item2 at 2, item1 at 3 item2.insert_at(1) # Now: item2 at 1, item3 at 2, item1 at 3 # Query operations item3.higher_items # [item2] item1.lower_items # [] item2.higher_item # item3 item1.last? # true ``` -------------------------------- ### Rescue and retry database deadlock errors Source: https://github.com/brendon/acts_as_list/blob/master/README.md A simple example of rescuing from ActiveRecord::Deadlocked and retrying the operation, suitable for Rails >= 5.1.0. ```ruby attempts_left = 2 while attempts_left > 0 attempts_left -= 1 begin TodoItem.transaction do TodoItem.create(todo_list: todo_list, position: 1) end attempts_left = 0 rescue ActiveRecord::Deadlocked raise unless attempts_left > 0 end end ``` -------------------------------- ### Batch updates preserving custom positions Source: https://github.com/brendon/acts_as_list/blob/master/_autodocs/api-reference/class-methods.md Example for batch updates where custom positions from a CSV file need to be preserved. ```ruby def import_items(file_path) TodoItem.acts_as_list_no_update do CSV.foreach(file_path) do |row| TodoItem.create( todo_list_id: row['list_id'], description: row['description'], position: row['position'] ) end end end # Items are created with exact positions from CSV # No position collisions or reordering happens ``` -------------------------------- ### Sequential Updates Strategy - Without Unique Constraint Source: https://github.com/brendon/acts_as_list/blob/master/_autodocs/architecture.md Example of a fast bulk update for items when there is no unique constraint on the position column. ```ruby # Without unique constraint: fast bulk update Item.where("position >= 5").increment_all ``` -------------------------------- ### DisparityClassesError How to Catch Source: https://github.com/brendon/acts_as_list/blob/master/_autodocs/errors.md Example of how to rescue DisparityClassesError. ```ruby begin TodoItem.acts_as_list_no_update([String]) do # ... end rescue ActiveRecord::Acts::List::NoUpdate::DisparityClassesError => e puts "Error: #{e.message}" end ``` -------------------------------- ### ArrayTypeError How to Catch Source: https://github.com/brendon/acts_as_list/blob/master/_autodocs/errors.md Example of how to rescue ArrayTypeError. ```ruby begin TodoItem.acts_as_list_no_update("not_an_array") do # ... end rescue ActiveRecord::Acts::List::NoUpdate::ArrayTypeError => e puts "Error: #{e.message}" end ``` -------------------------------- ### ArgumentError (from insert_at) How to Catch Source: https://github.com/brendon/acts_as_list/blob/master/_autodocs/errors.md Example of how to rescue ArgumentError for insert_at. ```ruby begin item.insert_at(0) rescue ArgumentError => e puts "Error: #{e.message}" end ``` -------------------------------- ### Soft-Delete Integration Source: https://github.com/brendon/acts_as_list/blob/master/_autodocs/README.md Example of integrating acts_as_list with soft-delete functionality. ```ruby class Item < ApplicationRecord acts_as_paranoid acts_as_list scope: [:list_id, { deleted_at: nil }] end ``` -------------------------------- ### How to Catch Database-Level Errors Source: https://github.com/brendon/acts_as_list/blob/master/_autodocs/errors.md Example of how to catch RecordInvalid and RecordNotFound errors. ```ruby begin item.insert_at!(5) rescue ActiveRecord::RecordInvalid => e puts "Validation failed: #{e.message}" rescue ActiveRecord::RecordNotFound => e puts "Record not found: #{e.message}" end ``` -------------------------------- ### ArgumentError (from insert_at) with Custom top_of_list Source: https://github.com/brendon/acts_as_list/blob/master/_autodocs/errors.md Example of ArgumentError with a custom top_of_list configuration. ```ruby class Item < ActiveRecord::Base acts_as_list top_of_list: 0 end item = Item.find(1) # Raises ArgumentError item.insert_at(-1) # Correct usage item.insert_at(0) item.insert_at(1) ``` -------------------------------- ### DisparityClassesError Trigger Condition Source: https://github.com/brendon/acts_as_list/blob/master/_autodocs/errors.md Examples demonstrating when DisparityClassesError is raised and correct usage. ```ruby # Raises DisparityClassesError TodoItem.acts_as_list_no_update([String, Integer]) do TodoItem.find(1).update(position: 2) end # Raises DisparityClassesError TodoItem.acts_as_list_no_update([TodoItem, "NotAClass"]) do TodoItem.find(1).update(position: 2) end # Correct usage TodoItem.acts_as_list_no_update([TodoItem, TodoAttachment]) do TodoItem.find(1).update(position: 2) end ``` -------------------------------- ### ArrayTypeError Trigger Condition Source: https://github.com/brendon/acts_as_list/blob/master/_autodocs/errors.md Example demonstrating when ArrayTypeError is raised and correct usage. ```ruby # Raises ArrayTypeError TodoItem.acts_as_list_no_update("TodoItem") do TodoItem.find(1).update(position: 2) end # Correct usage (array) TodoItem.acts_as_list_no_update([TodoItem]) do TodoItem.find(1).update(position: 2) end ``` -------------------------------- ### default_position? Method Signature Source: https://github.com/brendon/acts_as_list/blob/master/_autodocs/api-reference/instance-methods.md The signature for the default_position? method. ```ruby def default_position? ``` -------------------------------- ### Deadlock-Safe Operations Source: https://github.com/brendon/acts_as_list/blob/master/_autodocs/README.md Example of implementing deadlock-safe operations when reordering list items. ```ruby def move_with_retry(item_id, position) retries = 0 begin Item.transaction { Item.find(item_id).insert_at(position) } rescue ActiveRecord::Deadlocked retry if (retries += 1) < 3 end end ``` -------------------------------- ### Disable for specific classes Source: https://github.com/brendon/acts_as_list/blob/master/_autodocs/README.md Example of disabling acts_as_list callbacks for specific classes. ```ruby TodoItem.acts_as_list_no_update([TodoAttachment]) do # TodoItem callbacks disabled, TodoAttachment disabled, others enabled end ``` -------------------------------- ### No automatic positioning on creation Source: https://github.com/brendon/acts_as_list/blob/master/_autodocs/api-reference/acts-as-list.md Example of disabling automatic positioning for new records. ```ruby class CustomOrderedItem < ActiveRecord::Base acts_as_list add_new_at: nil end item = CustomOrderedItem.create item.current_position # => nil until explicitly set ``` -------------------------------- ### ArgumentError for Invalid Position Source: https://github.com/brendon/acts_as_list/blob/master/_autodocs/architecture.md An example of raising an ArgumentError when an invalid position is provided to insert_at. ```ruby raise ArgumentError.new("position cannot be lower than top") if position < acts_as_list_top ``` -------------------------------- ### Integration Point Source: https://github.com/brendon/acts_as_list/blob/master/_autodocs/architecture.md How the gem integrates into ActiveRecord via ActiveSupport.on_load. ```ruby # lib/acts_as_list/active_record/acts/active_record.rb ActiveSupport.on_load :active_record do extend ActiveRecord::Acts::List::ClassMethods end ``` -------------------------------- ### Single scope configuration Source: https://github.com/brendon/acts_as_list/blob/master/README.md Example of configuring acts_as_list with a single scope on a non-association field like 'task_category'. ```ruby class TodoItem < ActiveRecord::Base # `task_category` is a plain text field (e.g. 'work', 'shopping', 'meeting'), not an association acts_as_list scope: [:task_category] end ``` -------------------------------- ### Use Transactions Source: https://github.com/brendon/acts_as_list/blob/master/_autodocs/errors.md Example of wrapping position-changing operations within a database transaction to ensure atomicity. ```ruby TodoItem.transaction do item.insert_at(5) other_item.move_higher end ``` -------------------------------- ### ArgumentError (from insert_at) Trigger Condition Source: https://github.com/brendon/acts_as_list/blob/master/_autodocs/errors.md Examples demonstrating when ArgumentError is raised for insert_at and correct usage. ```ruby # Default top_of_list is 1 item = TodoItem.find(1) # Raises ArgumentError item.insert_at(0) item.insert_at(-1) # Correct usage item.insert_at(1) item.insert_at(5) ``` -------------------------------- ### Sequential Updates Strategy - With Unique Constraint Source: https://github.com/brendon/acts_as_list/blob/master/_autodocs/architecture.md Illustrates one-by-one updates to avoid conflicts when a unique constraint exists on the position column. ```ruby # With unique constraint: one-by-one to avoid conflicts [item1, item2, item3].each { |item| item.increment_all } ``` -------------------------------- ### move_to_top Method Signature Source: https://github.com/brendon/acts_as_list/blob/master/_autodocs/api-reference/instance-methods.md The signature for the move_to_top instance method. ```ruby def move_to_top end ``` -------------------------------- ### Disable for multiple classes Source: https://github.com/brendon/acts_as_list/blob/master/_autodocs/api-reference/class-methods.md Example showing how to disable position updates for multiple classes simultaneously. ```ruby class TodoList < ActiveRecord::Base has_many :todo_items acts_as_list end class TodoItem < ActiveRecord::Base belongs_to :todo_list has_many :todo_attachments acts_as_list scope: :todo_list end class TodoAttachment < ActiveRecord::Base belongs_to :todo_item acts_as_list scope: :todo_item end # Disable updates for TodoItem and TodoAttachment, but not TodoList TodoItem.acts_as_list_no_update([TodoAttachment]) do TodoItem.find(10).update(position: 2) # Callbacks disabled TodoAttachment.find(10).update(position: 1) # Callbacks disabled TodoAttachment.find(11).update(position: 2) # Callbacks disabled TodoList.find(2).update(position: 3) # Callbacks ENABLED ``` -------------------------------- ### move_to_bottom Method Signature Source: https://github.com/brendon/acts_as_list/blob/master/_autodocs/api-reference/instance-methods.md The signature for the move_to_bottom instance method. ```ruby def move_to_bottom end ``` -------------------------------- ### Timestamp Updates with touch_on_update: true Source: https://github.com/brendon/acts_as_list/blob/master/_autodocs/configuration.md Demonstrates how the `updated_at` timestamp is modified when `touch_on_update` is true and an item's position is changed. ```ruby item = TodoItem.find(1) item.updated_at # => 2023-01-01 10:00:00 item.move_higher item.updated_at # => 2023-01-01 10:00:05 (updated) ``` -------------------------------- ### Disable for calling class only Source: https://github.com/brendon/acts_as_list/blob/master/_autodocs/api-reference/class-methods.md Example demonstrating how to temporarily disable position updates for the calling class only. ```ruby class TodoItem < ActiveRecord::Base acts_as_list scope: :todo_list end # Temporarily disable position updates TodoItem.acts_as_list_no_update do TodoItem.find(1).update(position: 2) # Position not updated TodoItem.find(2).update(position: 1) # Position not updated end # After block, callbacks are re-enabled TodoItem.find(1).move_higher # Callbacks work normally ``` -------------------------------- ### Version Compatibility Check Source: https://github.com/brendon/acts_as_list/blob/master/_autodocs/architecture.md Ruby code snippet demonstrating how to check for compatibility with ActiveRecord versions using Gem::Requirement. ```ruby version = Gem.loaded_specs['activerecord'].version requirement = Gem::Requirement.new('>= 5.1') requirement.satisfied_by?(version) ``` -------------------------------- ### Behavior: Disabling Timestamp Updates Source: https://github.com/brendon/acts_as_list/blob/master/_autodocs/api-reference/usage-patterns.md Shows that updated_at remains unchanged after moving an item when touch_on_update is false. ```ruby item = MenuItem.find(1) item.updated_at # 2023-01-01 10:00:00 item.move_higher item.updated_at # Still 2023-01-01 10:00:00 (unchanged) item.reload.updated_at # Confirmed unchanged in database ``` -------------------------------- ### Callback Architecture Source: https://github.com/brendon/acts_as_list/blob/master/_autodocs/architecture.md ActiveRecord callbacks used by acts_as_list to manage positions. ```ruby before_validation :check_top_position before_destroy :reload after_destroy :decrement_positions_on_lower_items before_update :check_scope after_update :update_positions after_save :clear_scope_changed before_create :avoid_collision ``` -------------------------------- ### default_position Method Signature Source: https://github.com/brendon/acts_as_list/blob/master/_autodocs/api-reference/instance-methods.md The signature for the default_position method. ```ruby def default_position ```