A Ruby gem for managing ordered lists in Active Record models with scoped positioning and gap-free sequences.
Positioning is a Ruby gem that provides ordered list functionality for Active Record models. It solves the problem of managing item positions within scoped lists (e.g., tasks in a project, menu items in a category) while maintaining sequential, gap-free integer positions. The gem handles position updates, scope changes, and concurrency safety automatically.
Ruby on Rails developers building applications with ordered lists, such as task managers, content management systems, or any interface where drag-and-drop or manual ordering is required.
Developers choose Positioning for its simplicity, robust scope support, and concurrency safety. Unlike basic solutions, it avoids position gaps, supports complex scopes (including polymorphic associations), and integrates seamlessly with Rails forms via relative positioning.
Simple positioning for Active Record models.
Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.
Handles global, simple, and complex scopes including polymorphic associations, as shown in the `positioned` method examples with arrays like [:list, :category, :enabled].
Automatically maintains sequential integer positions without gaps, with a built-in `heal_position_column!` method to fix existing data, ensuring clean list ordering.
Uses row locking to prevent race conditions during updates, as mentioned in the concurrency section, making it reliable for multi-user environments.
Supports moving items with `before:` or `after:` references instead of manual integer assignments, simplifying list manipulations in code.
Provides `Positioning::RelativePosition` Struct for easy form integration, allowing relative positioning via Rails form helpers as detailed in the form examples.
Row locking isn't supported in SQLite, leading to potential 'database locked' errors under high write loads, as admitted in the concurrency section.
Healing existing position columns and adding database constraints (e.g., unique indexes) require manual steps, which can be cumbersome for large or messy datasets.
Does not work with abstract subclasses or single table inheritance (STI) without explicitly scoping by the `type` column, reducing flexibility for some Rails patterns.
Requires specific non-NULL constraints and unique indexes on scope and position columns, adding complexity to schema management and potential migration headaches.