# Is this safe?

**URL:** <https://www.ruby-forum.com/t/is-this-safe/192092>\
**Category:** Rails\
**Created:** [July 23, 2010, 5:30pm UTC](https://www.ruby-forum.com/t/is-this-safe/192092 "2010-07-23T17:30:27Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![dee](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/58956e/32.png) [@dee](https://www.ruby-forum.com/u/dee)\
**Post date:** [July 23, 2010, 5:30pm UTC](https://www.ruby-forum.com/t/is-this-safe/192092/1 "2010-07-23T17:30:27Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![dee](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/58956e/32.png) [@dee](https://www.ruby-forum.com/u/dee)\
**Post date:** [July 23, 2010, 6:07pm UTC](https://www.ruby-forum.com/t/is-this-safe/192092/2 "2010-07-23T18:07:20Z")

</div>

On Jul 23, 2010, at 8:28 AM, Dee wrote:

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

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

---

<div class="post-metadata">

**Author:** ![dee](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/58956e/32.png) [@dee](https://www.ruby-forum.com/u/dee)\
**Post date:** [July 23, 2010, 11:53pm UTC](https://www.ruby-forum.com/t/is-this-safe/192092/3 "2010-07-23T23:53:54Z")

</div>

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.
