brendon / acts_as_list

An ActiveRecord plugin for managing lists.
http://brendon.github.io/acts_as_list/
MIT License
2.04k stars 355 forks source link

Skip acts_as_list conditionally #440

Closed tanay-bacancy closed 1 week ago

tanay-bacancy commented 1 week ago

I am using a single model for acts_as_list, not sure if it is mandatory to add an associated model.

class TestModel < ApplicationRecord
  # need to skip adding a value to position for a specific condition or add position for a specific condition
  acts_as_list , if: Proc.new { |test| test.field == 'SomeValue' } # not working
  acts_as_list add_new_at: nil, scope: [field: 'SomeValue'] # it adds nil for all cases
end

Tried multiple combinations

brendon commented 1 week ago

Hi @tanay-bacancy, try my other gem: https://github.com/brendon/positioning

It allows for a single list for the whole model (scopeless). I'm not sure if acts_as_list supports this off the top of my head.

tanay-bacancy commented 1 week ago

Hi @tanay-bacancy, try my other gem: https://github.com/brendon/positioning

It allows for a single list for the whole model (scopeless). I'm not sure if acts_as_list supports this off the top of my head.

Thanks for the suggestion, I am trying the gem but could not find the specific usage (conditionally) and with simple integration is it not working positions are [0,1] only

brendon commented 1 week ago

Sorry @tanay-bacancy, I don't know quite what you mean. The documentation on the homepage or positioning covers using it without a scope. It's as simple as calling positioned. If you have some kind of condition, then that is actually a scope. If it's true or false only then it basically splits the model into two lists and that's ok.