instance method
child!
Ruby on Rails 2.13.0
Since v2.4.1 Last seen in v2.14.1Signature
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
# File lib/jbuilder.rb, line 177
def child!
@attributes = [] unless ::Array === @attributes
@attributes << _scope{ yield self }
end
Defined in lib/jbuilder.rb line 177
· View on GitHub
· Improve this page
· Find usages on GitHub
Defined in Jbuilder