module NestedForm::BuilderMixin

Public Instance Methods

fields_for_nested_model(name, object, options, block) click to toggle source
Calls superclass method
# File lib/nested_form/builder_mixin.rb, line 90
def fields_for_nested_model(name, object, options, block)
  classes = 'fields'
  classes << ' marked_for_destruction' if object.respond_to?(:marked_for_destruction?) && object.marked_for_destruction?

  perform_wrap   = options.fetch(:nested_wrapper, true)
  perform_wrap &&= options[:wrapper] != false # wrap even if nil

  if perform_wrap
    @template.content_tag(:div, super, :class => classes)
  else
    super
  end
end
fields_for_with_nested_attributes(association_name, *args) click to toggle source
Calls superclass method
# File lib/nested_form/builder_mixin.rb, line 74
def fields_for_with_nested_attributes(association_name, *args)
  # TODO Test this better
  block = args.pop || Proc.new { |fields| @template.render(:partial => "#{association_name.to_s.singularize}_fields", :locals => {:f => fields}) }

  options = args.dup.extract_options!

  # Rails 3.0.x
  if options.empty? && args[0].kind_of?(Array)
    options = args[0].dup.extract_options!
  end

  @fields ||= {}
  @fields[fields_blueprint_id_for(association_name)] = { :block => block, :options => options }
  super(association_name, *(args << block))
end

Private Instance Methods

fields_blueprint_id_for(association) click to toggle source
# File lib/nested_form/builder_mixin.rb, line 106
def fields_blueprint_id_for(association)
  assocs = object_name.to_s.scan(/(\w+)_attributes/).map(&:first)
  assocs << association
  assocs.join('_') + '_fields_blueprint'
end