Skip to content

Commit

Permalink
Enhance example for to disambiguates expected output
Browse files Browse the repository at this point in the history
  • Loading branch information
inkstak authored and palkan committed Dec 13, 2024
1 parent 14add12 commit 26f7987
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions docs/reasons.md
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,23 @@ Sometimes details could be useful not only to provide more context to the user,

In this cases, digging through the `ex.result.reasons.details` could be cumbersome (see [this PR](https://github.com/palkan/action_policy/pull/130) for discussion). We provide a helper method, `result.all_details`, which could be used to get all details merged into a single Hash:

```ruby
class PostPolicy < ApplicationPolicy
def edit?
check?(:published?)
end
def published?
details[:not_found] = true
record.published?
end
end
```

```ruby
p ex.result.all_details #=> {not_found: true}
```

```ruby
rescue_from ActionPolicy::Unauthorized do |ex|
if ex.result.all_details[:not_found]
Expand Down

0 comments on commit 26f7987

Please sign in to comment.