We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent ec15fa9 commit 1e13c91Copy full SHA for 1e13c91
docs/general/serializers.md
@@ -34,6 +34,18 @@ Serialization of the resource `title`
34
| `attribute :title { 'A Different Title'}` | `{ title: 'A Different Title' } `
35
| `attribute :title`<br>`def title 'A Different Title' end` | `{ title: 'A Different Title' }`
36
37
+An `if` or `unless` parameter can make an attribute conditional. It take a symbol of a method name on the serializer.
38
+
39
+e.g.
40
41
+```ruby
42
+attribute :private_data, if: :is_current_user?
43
44
+def is_current_user?
45
+ object.id == current_user.id
46
+end
47
+```
48
49
[PR please for conditional attributes:)](https://github.com/rails-api/active_model_serializers/pull/1403)
50
51
### Associations
0 commit comments