News for hackers. Stuff that matters.
Re:Should "Yes, delete it" be red, or green? by mbesto on Thursday March 27, 2014 @12:52AM (#7478674)
I 100% agree `Undo` is the best way to go about this. Equally, I'm very curious to hear how others have implemented this in their app. The complexity for such a small feature is actually quite high, because we start playing with the database (and therefore, in many cases a robust ORM)

Anyone have experience with doing something like this in Rails?

Re:Should "Yes, delete it" be red, or green? by ericingram on Thursday March 27, 2014 @01:12AM (#7478733)
We solve it using an "archive" collection in mongodb. Deleting moves a document from one collection to the archive, while undo moves it back.

We also implement ability to find deleted documents by id, by searching the archive if the record is not found in the original collection.

API looks like this:

    // delete something
    delete("/products/123")
    
    // see it in the archive
    get("/archive/products/123")
    
    // undelete it
    put("/products/123", {$restore: true})
Re:Should "Yes, delete it" be red, or green? by ForHackernews on Thursday March 27, 2014 @01:12AM (#7478734)
One simple implementation is just to queue up the action without committing it, then "undo" actually just cancels a pending action. The downside of this approach is "undo" becomes a limited time only offer.
Re:Should "Yes, delete it" be red, or green? by weavie on Thursday March 27, 2014 @04:51AM (#7479251)
I just stick an isDeleted column on my tables. It does mean I have to remember to do a `where !isDeleted` on all my main queries, but apart from that the cost of undoing is incredibly cheap.
Re:Should "Yes, delete it" be red, or green? by runner84111 on Thursday March 27, 2014 @02:21AM (#7478910)
Actual deletion occurs on app close (or next open). The "delete" the user sees just hides the data.