What does remove_from_list actually do?

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?

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.

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