brendon / acts_as_list

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

Added fixed values option for scope array #286

Closed smoyte closed 7 years ago

smoyte commented 7 years ago

Hi there. Thanks for all the awesome work on this classic gem.

I'm suggesting the ability to include fixed values in the scope array so that I can ignore soft deleted items (via acts_as_paranoid).

Someone had suggested using a string scope for this but I was encountering a bug with that when moving an object from one scope to another -- it wasn't resetting the position to 1, even though it is able to do that correctly with the identical scope but in array format.

Debugging that was going to be tough so I went for this instead, since it's nicer/more readable syntax anyway IMO. If you want me to file an issue for the bug I can do that also.

Hope you like this!

smoyte commented 7 years ago

Oh, FYI, simply using deleted_at as a regular scope param doesn't work because on destroy, deleted_at gets set first before AAL tries to do its rank adjustments.

brendon commented 7 years ago

Hi @hooverlunch, thank you for your contribution! :)

In the past I've done things like this for complex scopes: https://github.com/swanandp/acts_as_list/issues/158#issuecomment-211116767

Though this solution looks good too. @swanandp, what do you think? I'm happy to merge it as it's quite useful and I don't think it breaks any of the current API.

brendon commented 7 years ago

Thanks @swanandp. Released as 0.9.9. Great work!

smoyte commented 7 years ago

Yay! Thanks you all for the prompt response!

joshuapinter commented 6 years ago

Great friggin' work, @hooverlunch! Really cleans up complex scopes. 👍