Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get Rails' acts_as_list to add new items to the beginning of a list?

I have a model integrated with acts_as_list. However, by default new items created get added to the end of the list. Is there a default way to add new items to the beginning?

Thanks!

like image 962
Yuval Karmi Avatar asked Aug 22 '12 22:08

Yuval Karmi


2 Answers

Try using the add_new_at configuration option:

acts_as_list scope: :todo, add_new_at: :top
like image 66
drewish Avatar answered Nov 15 '22 06:11

drewish


You can change the way the list items are displayed to begin with. Reversing the order of todo_items effectively accomplishes that.

has_many :todo_items, :order => "position ASC"

Otherwise, perhaps you can set the position column on the items manually in an after_create.

like image 34
bevanb Avatar answered Nov 15 '22 06:11

bevanb