Is this safe?

I was surprised to see this redirect worked:

# FYI Project has_many Tasks, and Task belongs_to Project

# Task controller

  def destroy
    @task = Task.find(params[:id])
    @task.destroy
    flash[:notice] = "Successfully destroyed task."
    redirect_to @task.project
  end

I assume that clean up doesn't happen until after destroy. Seems that
'project' should be cached before @task.destroy or is it actually safe
to use this way? I'd think this might be one of those places where
production might behave differently from development and test.

Rails 3.0.0.beta4
Ruby 1.8.7

Well, this is fine as long as you don't have the :dependent => :destroy option set on the task/project relationship.

You can destroy an object and still have access to it. You just can't modify it, etc... it's gone from the DB, but you're "@task" object is still an object.

If you call @task.frozen? it will return true which may/may-not be useful to you.

-philip

Thanks, Philip, for a thorough response. Of course you're right. I see
your point with the dependent_destroy -- but task is the dependent in
the relationship so I think I'm okay.