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:
9
9
Fixes:
10
10
11
11
Misc:
12
+ - [ #1734 ] ( https://github.com/rails-api/active_model_serializers/pull/1734 ) Adds documentation for conditional attribute (@lambda2 )
12
13
13
14
### [ v0.10.0 (2016-05-17)] ( https://github.com/rails-api/active_model_serializers/compare/4a2d9853ba7...v0.10.0 )
14
15
Original file line number Diff line number Diff line change @@ -34,7 +34,18 @@ Serialization of the resource `title`
34
34
| ` attribute :title { 'A Different Title'} ` | ` { title: 'A Different Title' } `
35
35
| ` attribute :title ` <br >` def title 'A Different Title' end ` | ` { title: 'A Different Title' } `
36
36
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
+ ```
38
49
39
50
### Associations
40
51
You can’t perform that action at this time.
0 commit comments