-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adding documentation on conditional attributes #1734
Conversation
@@ -34,6 +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' }` | |||
|
|||
An `if` or `unless` parameter can make an attribute conditional. It take a symbol of a method name on the serializer. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/take/takes/
Thanks for this PR! I think we merged the PR allowing lambdas as values for the |
object.id == current_user.id | ||
end | ||
``` | ||
|
||
[PR please for conditional attributes:)](https://github.com/rails-api/active_model_serializers/pull/1403) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this breadcrumb taken care of then?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yup, seems so. Good catch @cgmckeever. @lambda2 could you remove the reminder?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yup !
@lambda2 great! would you like to add yourself to the changelog under misc or rebase? If not, we can handle it. |
@bf4 Yes, I added it under misc :) |
@lambda2 Thanks very much for this! Could you do the following:
Once those items are taken care of we can get this merged in. |
@remear yeah, of course. Seems good now ! |
@@ -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` parameter can make an attribute conditional. It takes a symbol of a method name on the serializer, or a lambda literal. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd rather use option
instead of parameter
here.
Adding documentation and short example ([from this pull request](rails-api#1403)) on conditional attributes. Adding lambda literal notation and example. Adding lambda literal notation and example, and fixing typo. Removing PR reminder Adding Changelog entry Moving CHANGELOG entry under master (unreleased) Use option instead of parameter
👌 |
Purpose
Adding documentation on conditional attributes for the
attribute
method.Changes
Adding documentation and short example (from this pull request) on conditional attributes for the
attribute
method.Related GitHub issues
#1403