The CRUD principle defines the four basic operations on persistent data:
- Create,
- Read,
- Update,
- Delete.
HTTP verbs also use the DELETE word.
Why does the default routing in Rails use the word "destroy" for the action corresponding to the HTTP verb DELETE?
For the model part, here is a nice summary from http://www.nickpeters.net/2007/12/21/delete-vs-destroy/:
Knowing that, it only makes sense to call the action in the controller the same as the one in the model. Delete is too simplistic.
Rails uses 4 standard methods(verbs), namely:
Besides it has 7 RESTful actions:
Rails never uses the same verb as the corresponding action. Routing to the action destroy makes it possible to do more than a single DELETE, through the corresponding action in the controller.
This railsguide might be of interest to you: http://guides.rubyonrails.org/routing.html
Explanation
Now, imagine we have a HTTP GET request, which means you want to read/retrieve data. If the action would have the same name as the verb, GET in this case, it would be overly simplistic. GET can give access to show, index, new or edit actions. They all read data, but the actions themselves are definitely not the same. The same could be said about the DELETE request. This request is processed through the controller and can have different implementations within actions. It might be you want to destroy a post, but it might as well mean you want to log out of your user session. Only having an action called delete would not justify the possibilities related to it, through the controller.
Edit
If you want to know more about how requests from the browser are processed, you could read some information about the M(odel)V(iew)C(ontroller)-model that Rails uses:
http://www.youtube.com/watch?v=3mQjtk2YDkM&noredirect=1
and:
http://betterexplained.com/articles/intermediate-rails-understanding-models-views-and-controllers/
A quote from this link:
Meaning your initial request will be translated and processed through the webserver and the correct route has to be defined through the controller, where the restful action, such as destroy, is located.
In the early days of Rails, there were only 2 verb's, namely GET and POST (since PUT and DELETE are not supported, which later versions of rails resolved by adding PUT and DELETE through hidden variables. The name of the destroy action never changed, since request and actions are two different things.
This quote may be of further interest:
http://guides.rubyonrails.org/routing.html
Here is an very early(2007) answer from Ryan Bates
source
Good question.
I feel like it's to encourage you to always use
destroy
and notdelete
on your objects.Actually,
delete
doesn't trigger any callback.