Scaffold_resouce destroy

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.

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