Closed rctneil closed 9 months ago
Hi @rctneil,
See here: https://github.com/brendon/acts_as_list?tab=readme-ov-file#more-options
column
lets you change the column used in the model.
NULL
is considered "not in the list" and there isn't much of a way around that unfortunately.
Standard usage of the gem is just to set the position
column to the desired position then save and let the callbacks do the rest. Alternatively if you don't set it and save, the gem will add the item to the end of the list.
@brendon Thank you. Ah!!! I looked for an options section and obviously completely missed it! Apologies for that.
Ok, is it the same for 0? I have a lot of items in my app that need positioning and i've just set up a UI to order them but the position is currently NULL. I could change them in bulk to 0 or 1 I guess?
Do you think that would work?
Hehe, I hate to do this but:
https://github.com/brendon/acts_as_list?tab=readme-ov-file#adding-acts_as_list-to-an-existing-model
There's a doc for that too :D You do need to pre-populate the column in order for things to work properly.
Hey,
It's not really that. Basically I have a model with acts as list which is scoped to an association. I need to run through eat set of items and check the order. So, if I can view them in my UI as all 0's or all 1's etc then I can tell that one needs me to manually set their orders. If I see a set with 1, 2, 3 etc, then I know the order is already correct. The issue is that if I manually update in my DB all the NULL values to 0, then using move_higher
does not seem to have any effect. I was asking whether setting them all the 1's would work? or do they all have to be different within the scope?
Sorry, I really hope that makes more sense!! :-)
Yep that makes sense. You definitely need them to all have different values. By default that's integers from 1
and upward with no gaps.
Ok. Thanks for the reply. I thought that may be the case. Looks like I'll have to do something like your example script that iterates each item and adds index values and then just manually double check their orders.
Appreciate your help!
No worries :D
Hi,
Is there a config option to change the field name? I'd like the filed to be used to be called "time" on one model and "order_ridden" on another one.
Secondly, is there a way to get the order to populate correctly from 0 or NULL values? Eg, if i ahve a record with a NULL position and call .move_higher, I'd like that to get set to 1.
Thanks