KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I think it important to have an " undo " method ala gmail when destroying records instead of displaying an annoying popup that says, " Are you sure? ". The way that I've implemented this is to have a "deleted_at" timestamp column in the model which gets timestamped when destroy method is called def destroy @foo = Foo.find(params[:id]) @foo.update_attribute(:deleted_at, Time.now) ... end To revert/undo I'll just set the same column to nil def revert @foo = Foo.find(params[:id]) @foo.update_attribute(:deleted_at, nil) ... end I'll just have to add a condition to filter off "deleted" foos when I call the find method. Perhaps set a cron or background task to really destroy "deleted" foos after some time. Works for me and easy to implement but I'm curious as to if there's a better way to implement this feature? Maybe there's a plugin or gem that provides this that I don't know about?
Tags (comma-separated)
Save Edits
Cancel