Topic: Beware acts_as_list

I have just nailed it... Spent 5 hours troubleshooting weird occurences in my database. No help in logs, my code looked clean, yet, weird changes in my model values... Read on...

I have a custom app for 'members' who have 'images'. Long story short, members upload images, can sort them and so on. Used sortable_list add-on which recommended using acts_as_list for my images.

In testing phase, my client had found a weird problem. When one member deleted his images, the order of another members' images would be messed up! I spent hours looking at my the 'position' attribute in my image objects in db. Couldn't figure out why the positions get magically altered, and nothing in the logs!

Turns out the acts_as_list plugin, which I never needed in the first place (sortable_list should not have recommened it), was messing up with my image model! It would arbitrarily alter all members' images for no reason! I commented it out

# acts_as_list

And back in business... No magical changes to my model anymore. Hope this help anyone. This dude had a similar problem I think...


Re: Beware acts_as_list

Looks like you've not discovered scopes with acts_as_list:

acts_as_list :scope => :member_id

or something like that. That tells acts_as_list to maintain a separate set of positions per parent member. Without that it'd be trying to maintain one giant list!

Hope that helps. Acts as list is ok, but I'm currently experiencing problems with deleting stuff! Sigh smile