Skip to content

Commit

Permalink
Add info on how to undiscard, and also how to work with Devise
Browse files Browse the repository at this point in the history
  • Loading branch information
w8m8 committed Mar 6, 2018
1 parent c3b29d1 commit c61fdb0
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,23 @@ def destroy
end
```


**Undiscard a record**

```
post = Post.first # => #<Post id: 1, ...>
post.undiscard # => true
```

***From a controller***

```
def update
@post.undiscard
redirect_to users_url, notice: "Post undiscarded"
end
```

**Working with associations**

Under paranoia, soft deleting a record will destroy any `dependent: :destroy`
Expand Down Expand Up @@ -165,6 +182,19 @@ class Post < ActiveRecord::Base
end
```

**Working with Devise**

A common use case is to apply discard to a User record. Even though a user has been discarded they can still login and continue their session.
If you are using Devise and wish for discarded users to be unable to login and stop their session you can override Devise's method.

```
class User < ActiveRecord::Base
def active_for_authentication?
super && !discarded_at
end
end
```

## Non-features

* Special handling of AR counter cache columns - The counter cache counts the total number of records, both kept and discarded.
Expand Down

0 comments on commit c61fdb0

Please sign in to comment.