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?
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?
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.
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.