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.