acts_as_list puts record at wrong position with array scope

764 Views Asked by At

I have a model with following setup for acts_as_list gem: acts_as_list scope: [parent_id: nil], add_new_at: :top, top_of_list: 0 I expect having next array of records: [Record id: 1, parent_id: nil, position: 1; Record id: 2, parent_id: nil, position: 0; Record id: 3, parent_id: 1, position: nil], but it happens like it ignores parent_id: nil and actual array of records is: [Record id: 1, parent_id: nil, position: 2; Record id: 2, parent_id: nil, position: 1; Record id: 3, parent_id: 1, position: 0]

1

There are 1 best solutions below

2
Brendon Muir On

s, it looks like you're trying to pass in a hash nested within an array for the scope. Try:

acts_as_list scope: { parent_id: nil }, add_new_at: :top, top_of_list: 0

alternatively, if you want a list for every seperate parent_id then use:

acts_as_list scope: :parent, add_new_at: :top, top_of_list: 0

acts_as_list will append the _id for you