Question

I use acts_as_list to generate slot numbers of books:

acts_as_list :scope => :book_id, :column => :slot

and have a default scope that prevents deleted (soft delete) books from getting in to result sets:

default_scope where(:is_active => true)

I want to prevent the default scope from getting applied to the acts_as_list declaration, because if someone deletes the last book, and creates a new one, they get the same slot number (because when it fetches the last slot number, the default scope gets applied and it doesn't get the deleted entry). I am aware of unscoped, but how do I use it with acts_as_list?

I am using Rails 3.0.11.

Was it helpful?

Solution 2

It seems that the older version (0.1.4) of the gem had some bug and unscoped.acts_as_list didn't prevent the default scope from getting applied. Updating the gem to the latest version (0.1.8) fixed it. By default, it doesn't apply the default scope, so we don't need to write unscoped.acts_as_list

More details can be found here:

https://github.com/swanandp/acts_as_list/pull/13

OTHER TIPS

wherever you use acts_as_list

just do this instead,

unscoped.acts_as_list
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top