instance method child!

Ruby on Rails 2.13.0

Since v2.4.1 Last seen in v2.14.1

Available in: v2.4.1 v2.5.0 v2.6.4 v2.7.0 v2.8.0 v2.9.1 v2.10.2 v2.11.5 v2.12.0 v2.13.0 v2.14.1

Signature

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

Type at least 2 characters to search.

↑↓ navigate · open · esc close