I've stumbled upon this Rails - acts_as_list with multiple Models. I'm having a hard time understanding how to fit the solution into my current use case.
In my app, I have a section. The section can hold many places
, checklists
, and notes
.
class Section < ApplicationRecord
has_many :places, -> { order(position: :asc) }, dependent: :destroy
has_many :notes, -> { order(position: :asc) }, dependent: :destroy
has_many :checklists, -> { order(position: :asc) }, dependent: :destroy
end
class Note < ApplicationRecord
acts_as_list scope: :section
belongs_to :section
end
class Place < ApplicationRecord
acts_as_list scope: :section
belongs_to :section
end
class Checklist < ApplicationRecord
acts_as_list scope: :section
belongs_to :section
end
What I'm aiming to do, is allow the user to drag around each place
, checklist
, or note
in the section. I've opted to use acts_as_list to manage positioning.
The problem I'm experiencing is, the scope
on each model isn't global to the section
. If I query data as section.places
The position of the items may be 1, 2, and 3
. If I query data as section.notes
The position could also be 1, 2, and 3
.
What I'm ultimately trying to do is tell acts_as_list
to order based on parent. Is this possible? Should I be looking more into polymorphic relationships to solve this problem?