# What does remove\_from\_list actually do?

**URL:** <https://www.ruby-forum.com/t/what-does-remove-from-list-actually-do/71316>\
**Category:** Rails\
**Created:** [October 6, 2006, 10:21pm UTC](https://www.ruby-forum.com/t/what-does-remove-from-list-actually-do/71316 "2006-10-06T22:21:07Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![jjkiesch](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/bc79bd/32.png) [@jjkiesch](https://www.ruby-forum.com/u/jjkiesch)\
**Post date:** [October 6, 2006, 10:21pm UTC](https://www.ruby-forum.com/t/what-does-remove-from-list-actually-do/71316/1 "2006-10-06T22:21:07Z")

</div>

i have a list of tasks that when completed, i don’t want to be on the  
list anymore. i tried using remove from list, expecting the tasks  
position column to be made null, but that didn’t work. any ideas?

---

<div class="post-metadata">

**Author:** ![jjkiesch](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/bc79bd/32.png) [@jjkiesch](https://www.ruby-forum.com/u/jjkiesch)\
**Post date:** [October 7, 2006, 3:41pm UTC](https://www.ruby-forum.com/t/what-does-remove-from-list-actually-do/71316/2 "2006-10-07T15:41:10Z")

</div>

Josh K. wrote:

> i have a list of tasks that when completed, i don’t want to be on the  
> list anymore. i tried using remove from list, expecting the tasks  
> position column to be made null, but that didn’t work. any ideas?

I’m not entirely sure what that method does, but even if it did work the  
way you describe, that’s not the best way t handle this situation.

You should have a boolean column on your list items called “completed”  
which defaults to false. When someone completed that task, set the  
completed column to true.

just make sure you properly setup your associatons. This should work.

class TodoList  
has\_many :tasks,  
:order =\> ‘position’

has\_many :open\_tasks,  
:conditions =\> [‘completed = ?’, false],  
:order =\> ‘position’,  
:class\_name =\> ‘Task’

has\_many :completed\_tasks,  
:conditions =\> [‘completed = ?’, true],  
:order =\> ‘position’  
:class\_name =\> ‘Task’  
end

now @list.open\_tasks and @list.completed\_tasks both return only their  
type of tasks, in their original orders. But @list.tasks still returns  
all tasks.

---

<div class="post-metadata">

**Author:** ![jjkiesch](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/bc79bd/32.png) [@jjkiesch](https://www.ruby-forum.com/u/jjkiesch)\
**Post date:** [October 7, 2006, 6:00pm UTC](https://www.ruby-forum.com/t/what-does-remove-from-list-actually-do/71316/3 "2006-10-07T18:00:23Z")

</div>

i figured it out. my solution actually ended up being close to what you  
had. i did have a completed\_at field that is null for all of the tasks  
that have not been completed.

when i completed a task, i set the completed\_at and also did  
task.remove\_from\_list

after working with it a while, i found out that it doesn’t set the  
position field to null necessarily, but when it “removes it from the  
list” it changes all of the other records so that they fill in the gap  
where it was removed.

hope that makes sense. everything seems to work great this way. thanks  
for the help
