Discard

Public
Installs Discard gem for soft deletes.
Icons/chart bar
Used 4 times
Created by
D Dale Zak

Usage
Migration
rails generate migration add_discarded_at_to_posts discarded_at:datetime:index

Model
class Post < ActiveRecord::Base
  include Discard::Model
end

Usage
Post.all             # => [#<Post id: 1, ...>]
Post.kept            # => [#<Post id: 1, ...>]
Post.discarded       # => []

post = Post.first   # => #<Post id: 1, ...>
post.discard        # => true
post.discard!       # => Discard::RecordNotDiscarded: Failed to discard the record
post.discarded?     # => true
post.undiscarded?   # => false
post.kept?          # => false
post.discarded_at   # => 2017-04-18 18:49:49 -0700

Post.all             # => [#<Post id: 1, ...>]
Post.kept            # => []
Post.discarded

Run this command in your Rails app directory in the terminal:

rails app:template LOCATION="https://railsbytes.com/script/z0gsEQ"
Template Source

Review the code before running this template on your machine.

run 'bundle add discard'
Comments

Sign up or Login to leave a comment.