module FreeForm::BuilderMixin

Public Instance Methods

fields_for_nested_model(name, object, options, block) click to toggle source
Calls superclass method
# File lib/freeform/builder/builder_mixin.rb, line 94
def fields_for_nested_model(name, object, options, block)
  perform_wrap   = options.fetch(:nested_wrapper, true)
  perform_wrap &&= options[:wrapper] != false # wrap even if nil

  if perform_wrap
    if object.respond_to?(:marked_for_destruction?) && object.marked_for_destruction?
      @template.content_tag(:div, super, :class => 'fields marked_for_destruction', :style => "display: none;")
    else
      @template.content_tag(:div, super, :class => 'fields')
    end
  else
    super
  end
end
fields_for_with_nested_attributes(association_name, *args) click to toggle source
Calls superclass method
# File lib/freeform/builder/builder_mixin.rb, line 79
def fields_for_with_nested_attributes(association_name, *args)
  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/freeform/builder/builder_mixin.rb, line 110
def fields_blueprint_id_for(association)
  assocs = object_name.to_s.scan(/(\w+)_attributes/).map(&:first)
  assocs << association
  assocs.join('_') + '_fields_blueprint'
end