File tree Expand file tree Collapse file tree 2 files changed +13
-1
lines changed Expand file tree Collapse file tree 2 files changed +13
-1
lines changed Original file line number Diff line number Diff line change @@ -9,6 +9,7 @@ Features:
99Fixes:
1010
1111Misc:
12+ - [ #1734 ] ( https://github.com/rails-api/active_model_serializers/pull/1734 ) Adds documentation for conditional attribute (@lambda2 )
1213
1314### [ v0.10.0 (2016-05-17)] ( https://github.com/rails-api/active_model_serializers/compare/4a2d9853ba7...v0.10.0 )
1415
Original file line number Diff line number Diff line change @@ -34,7 +34,18 @@ Serialization of the resource `title`
3434| ` attribute :title { 'A Different Title'} ` | ` { title: 'A Different Title' } `
3535| ` attribute :title ` <br >` def title 'A Different Title' end ` | ` { title: 'A Different Title' } `
3636
37- [ PR please for conditional attributes:)] ( https://github.com/rails-api/active_model_serializers/pull/1403 )
37+ 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.
38+
39+ e.g.
40+
41+ ``` ruby
42+ attribute :private_data , if: :is_current_user?
43+ attribute :another_private_data , if: -> { scope.admin? }
44+
45+ def is_current_user?
46+ object.id == current_user.id
47+ end
48+ ```
3849
3950### Associations
4051
You can’t perform that action at this time.
0 commit comments