Method: Jbuilder#child!
- Defined in:
- lib/jbuilder.rb
permalink #child! ⇒ Object
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
177 178 179 180 |
# File 'lib/jbuilder.rb', line 177 def child! @attributes = [] unless ::Array === @attributes @attributes << _scope{ yield self } end |