Skip to content

Commit

Permalink
Merge pull request #9 from almnes/improve-documentation
Browse files Browse the repository at this point in the history
Add info on how to undiscard, and also how to work with Devise
  • Loading branch information
jhawthorn authored Mar 16, 2018
2 parents c3b29d1 + c61fdb0 commit 1fa4ca7
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 1fa4ca7

Please sign in to comment.