0

What's the difference between delete and destroy?

If we generate a scaffold, the default method to remove an date entry is method: :delete, while delete is actually not defined in the controller. So how does rails actually figure out what to do?

4

2 回答 2

4

DELETE is HTTP verb while destroy is an action in the controller. If you use resources in your application, HTTP DELETE requests are routed to destroy action in the controller (unless you change the default behaviour).

method: :delete in link_to options means that clicking a link would trigger HTTP DELETE request.

于 2013-03-30T21:15:52.677 回答
-1

As far as I know:

Delete method uses an SQL DELETE statement without instantiating the objects or running any callback.

Destroy makes the SQL call to the database and deletes the row in the table where the current object is contained, you can still manage the object as long as you have it scoped.

Hope this helps.

于 2013-03-30T21:07:20.983 回答