class Padrino::Helpers::FormBuilder::AbstractFormBuilder
def fields_for(child_association, collection=nil, options={}, &block)
f.fields_for :addresses, @addresses
f.fields_for :addresses, address
f.fields_for :addresses
Supports nested fields for a child model within a form.
#
def fields_for(child_association, collection=nil, options={}, &block) default_collection = self.object.send(child_association) collection ||= default_collection include_index = default_collection.respond_to?(:each) nested_options = { :parent => self, :association => child_association } Array(collection).each_with_index.inject(ActiveSupport::SafeBuffer.new) do |all,(child_instance,index)| nested_options[:index] = options[:index] || (include_index ? index : nil) all << @template.fields_for(child_instance, { :nested => nested_options, :builder => self.class }, &block) << "\n" end end