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
  end

Source | Google | Stack overflow

Edit

git clone [email protected]:rails/jbuilder.git

cd jbuilder

open lib/jbuilder.rb

Contribute

# Make a new branch

git checkout -b -your-name--update-docs-Jbuilder-child--for-pr


# Commit to git

git add lib/jbuilder.rbgit commit -m "better docs for Jbuilder#child!"


# Open pull request

gem 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!