Skip to content

Commit

Permalink
Merge pull request #1734 from lambda2/patch-1
Browse files Browse the repository at this point in the history
Adding documentation on conditional attributes
  • Loading branch information
remear committed May 20, 2016
2 parents b5e2b41 + efdee60 commit 835aad3
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Features:
Fixes:

Misc:
- [#1734](https://github.com/rails-api/active_model_serializers/pull/1734) Adds documentation for conditional attribute (@lambda2)

### [v0.10.0 (2016-05-17)](https://github.com/rails-api/active_model_serializers/compare/4a2d9853ba7...v0.10.0)

Expand Down
13 changes: 12 additions & 1 deletion docs/general/serializers.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,18 @@ Serialization of the resource `title`
| `attribute :title { 'A Different Title'}` | `{ title: 'A Different Title' } `
| `attribute :title`<br>`def title 'A Different Title' end` | `{ title: 'A Different Title' }`

[PR please for conditional attributes:)](https://github.com/rails-api/active_model_serializers/pull/1403)
An `if` or `unless` option can make an attribute conditional. It takes a symbol of a method name on the serializer, or a lambda literal.

e.g.

```ruby
attribute :private_data, if: :is_current_user?
attribute :another_private_data, if: -> { scope.admin? }

def is_current_user?
object.id == current_user.id
end
```

### Associations

Expand Down

0 comments on commit 835aad3

Please sign in to comment.