# Scaffold\_resouce destroy

**URL:** <https://www.ruby-forum.com/t/scaffold-resouce-destroy/87936>\
**Category:** Rails\
**Created:** [March 7, 2007, 12:02am UTC](https://www.ruby-forum.com/t/scaffold-resouce-destroy/87936 "2007-03-07T00:02:49Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![rlwinter](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/ecccb3/32.png) [@rlwinter](https://www.ruby-forum.com/u/rlwinter)\
**Post date:** [March 7, 2007, 12:02am UTC](https://www.ruby-forum.com/t/scaffold-resouce-destroy/87936/1 "2007-03-07T00:02:49Z")

</div>

Hello group,

I ran across something while creating a client for my RESTful Rails  
application. My client is written in Cocoa (just FYI).

The scaffold\_resource generator writes the destory method like this:

# DELETE /articles/1

# DELETE /articles/1.xml

def destroy  
@article = Article.find(params[:id])  
@article.destroy

```
respond_to do |format|
  format.html { redirect_to articles_url }
  format.xml { head :ok }
end

```

end

During testing I realized that sending a request to delete an object  
id that does not exist (or was deleted by another user or process)  
results in a fairly ugly 500 - Internal Server Error and responds with  
the standard Rails error page HTML even when requesting XML format.

I can detect the status 500 error and report this to the user,  
however, I was wondering if there was a cleaner way to respond from  
the controller. Also, would it be useful for the scaffold\_resource  
generator to be modified to check the result of @article =  
Article.find(params[id]) before calling destroy, and respond with a  
more appropriate status? Is there a more appropriate status code for  
this operation?

Of course I could make the modifications myself for each controller,  
but just wanted to get the opinions of other Rails programmers.

---

<div class="post-metadata">

**Author:** ![rlwinter](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/ecccb3/32.png) [@rlwinter](https://www.ruby-forum.com/u/rlwinter)\
**Post date:** [March 7, 2007, 12:33am UTC](https://www.ruby-forum.com/t/scaffold-resouce-destroy/87936/2 "2007-03-07T00:33:52Z")

</div>

Hey,

the reason it’s blowing up _should_ be because Article.find(params  
[:id]) is raising a ActiveRecord::RecordNotFound

That exception will be returned as a 500 while in development mode.

If you’re in production mode and hitting a non-local url (not 127.1)  
then that exception should automatically be reported as a 404 - which  
is exactly what you want.

Regards,  
Trevor
