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

2 Questions #427

Closed rctneil closed 9 months ago

rctneil commented 9 months ago

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

brendon commented 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.

rctneil commented 9 months ago

@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?

brendon commented 9 months ago

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.

rctneil commented 9 months ago

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!! :-)

brendon commented 9 months ago

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.

rctneil commented 9 months ago

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!

brendon commented 9 months ago

No worries :D