-
Notifications
You must be signed in to change notification settings - Fork 438
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
ignore! function added #361
base: main
Are you sure you want to change the base?
Conversation
Thanks for the pull request, and welcome! The Rails team is excited to review your changes, and you should hear from @rwz (or someone else) soon. If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes. Please see the contribution instructions for more information. |
lib/jbuilder.rb
Outdated
# or empty array, you can pass a block. | ||
# | ||
# Example: | ||
# json.ignore { |value| value.nil? } |
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.
Shouldn't these say ignore!
?
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.
Yes it should. Thanks for pointing that out.
@abhiQmar Doesn't jbuilder already check for blank values? |
@nateberkopec No it doesn't, it makes sense if someone wants to blank arrays, nils and strings(for consistency) in their json output. But if you do not want any blank arrays or empty strings (my use case), you would have to put a check on each and every key-value pair. There is a method(ignore_nil!) to ignore the keys with nil values. I am just trying to extend this functionality so that we can check for anything on our keys cleanly, by sending a block [which if returns true will ignore the key-value pair]. |
8be11c8
to
23e05c0
Compare
Use case:
I had to write checks on each line to ignore keys with empty array or empty string values.
the above code now becomes: