This is simple enough.
I’m trying to use mongoid’s ‘after_destroy’ callback to do some cleanup operations.
Eg
class Model
include Mongoid::Document
after_destroy do |model|
#Do cleanup stuff
end
end
There are 2 ways to remove an object from mongo. Delete and Destroy. Destroy runs the callback but Delete Doesn’t.
The model’s routes are declared like this
resources :models
So my question is, when someone sends a request to models/delete does the destroy method get called or the delete method?
If the latter, then is there any way to run callbacks with the delete function in mongo.
The HTTP method :delete that gets created in
resources :modelshas no direct bearing on the method used in the model. the HTTP delete calls this method:You’re able to change “delete” to “destroy” in the controller to suit your needs.