0

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 Answer 1

0

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

2
  • first suggestion cause an exception when I create a new record and does rollback ActiveRecord::StatementInvalid (PG::SyntaxError: ERROR: syntax error at or near "{") Record Update All (1.0ms) UPDATE "records" SET "position" = ("records"."position" + 1), "updated_at" = '2019-12-11 08:34:42.166539' WHERE ({:parent_id=>nil}) Second is undesirable. And I pass it as hash to array because it will be changed in future to kind of [:status, parent_id: nil]. \s Thanks for answer.
    – mitsuka s
    Commented Dec 11, 2019 at 8:39
  • I'm a bit confused as to your actual requirements. They way you've written it, you seem to only want to maintain a list of parentless items (that's what providing the nil will do). The scope feature is meant to help us determine the other items that are in the same scope as the current record (thus you normally only provide the columns, not the values). Commented Dec 12, 2019 at 19:57

Not the answer you're looking for? Browse other questions tagged or ask your own question.