Skip to content

Commit

Permalink
docs(ability): fixes confusing ability check for Post.price
Browse files Browse the repository at this point in the history
Fixes #242
  • Loading branch information
stalniy committed Dec 18, 2019
1 parent 3404263 commit cbd252c
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions docs/_posts/2017-07-21-check-abilities.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,20 +61,20 @@ const ability = AbilityBuidler.define((can, cannot) => {
}
})

ability.throwUnlessCan('update', 'Post', 'price')
ability.throwUnlessCan('update', 'Product', 'price')
```

The code above will throw error with corresponding message, if user is not an admin.
Also that error object contains information about what `action`, `subject` and `field` were checked, so you can use this to provide template message and evaluate it later:

```js
try {
ability.throwUnlessCan('update', 'Post', 'price')
ability.throwUnlessCan('update', 'Product', 'price')
} catch (error) {
console.log(error.message) // "Only admins can update product prices"
console.log(error.action) // "update"
console.log(error.subjectName) // "Post"
console.log(error.subject) // "Post", does not equal `subjectName` when check on instance
console.log(error.subjectName) // "Product"
console.log(error.subject) // "Product", does not equal `subjectName` when check on instance
}
```

Expand Down

0 comments on commit cbd252c

Please sign in to comment.