Skip to content

Instantly share code, notes, and snippets.

@shunchu
Created October 23, 2014 20:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shunchu/6d229a9ce07b5e5ccfa9 to your computer and use it in GitHub Desktop.
Save shunchu/6d229a9ce07b5e5ccfa9 to your computer and use it in GitHub Desktop.
Add attributes to JBuilder collections
# this adds an additional `user_ids` array to each of the `organizations` collection
json.organizations do |json|
json.array! @organizations do |org|
json.merge! org.attributes
json.user_ids org.users.pluck(:id)
end
end
@shunchu
Copy link
Author

shunchu commented Oct 24, 2014

Or more simply, use the embed :ids, include: true syntax...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment