Reputation: 181
Excuse me, I am using soft_destroy to delete my data, and then I want to fix the deleted_by data when I try to delete it. So I used before_destroy in the model to do the processing. But it seems to have no effect. How can I do? Please tell me. thanks
Controller
def destroy
@project.soft_destroy
head :no_content
end
Model
before_destroy :deleted_by
private
def deleted_by
self.deleted_by = 101
end
After these executions, deleted_by does not become 101.
Upvotes: 0
Views: 354
Reputation: 154
Try on callback before_update because the record is not actually getting deleted.
Upvotes: 0
Reputation: 1598
You can do it in controller
before_action :set_project, only: [:show, :edit, :destroy, :update]
before_action :deleted_by, only: [:destroy]
private
def set_project
@project = Project.find(params[:id])
end
def deleted_by
@project.deleted_by = 101
end
Upvotes: 2