brendon/acts_as_list

Skip acts_as_list conditionally

tanay-bacancy opened this issue · 3 comments

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

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.

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

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.