jbuilder
https://github.com/rails/jbuilder
Ruby
Jbuilder: generate JSON objects with a Builder-style DSL
Jbuilder#child!
Turns the current element into an array and yields a builder to add a hash.
Example:
json.comments do
json.child! { json.content "hello" }
json.child! { json.content "world" }
end
{ "comments": [ { "content": "hello" }, { "content": "world" } ]}
More commonly, you'd use the combined iterator, though:
json.comments(@post.comments) do |comment|
json.content comment.formatted_content
endEdit
git clone [email protected]:rails/jbuilder.git
cd jbuilder
open lib/jbuilder.rb
Contribute
# Make a new branchgit checkout -b -your-name--update-docs-Jbuilder-child--for-pr
# Commit to gitgit add lib/jbuilder.rbgit commit -m "better docs for Jbuilder#child!"
# Open pull requestgem install hub # on a mac you can `brew install hub`
hub fork
git push <your name> -your-name--update-docs-Jbuilder-child--for-pr
hub pull-request
# Celebrate!