Translate

October 16, 2013

What is the difference between delete and destroy in Rails?

The delete method essentially deletes a row (or an array of rows) from the database.
Destroy on the other hand allows for a few more options. First, it will check any callbacks such as before_delete, or any dependencies that we specify in our model. Next, it will keep the object that just got deleted in memory, this allows us to leave a message saying something like “ 'Object_name' has been deleted.” Lastly, and most importantly, it will also delete any child objects associated with that object!
Post a Comment