lib/labelify.rb
# Taken directly from Rails fields_for implementation
Taken directly from Rails fields_for implementation
Taken directly from Rails fields_for implementation
def fields_for(record_or_name_or_array, *args, &block)
      if options.has_key?(:index)
        index = "[#{options[:index]}]"
      elsif defined?(@auto_index)
        self.object_name = @object_name.to_s.sub(/\[\]$/,"")
        index = "[#{@auto_index}]"
      else
        index = ""
      end
      args << {} unless args.last.is_a?(Hash)
      args.last.merge!(@options.slice(:no_label_for, :error_placement, :label_placement))
      args.last[:builder] ||= options[:builder] || Labelify::FormBuilder
      case record_or_name_or_array
      when String, Symbol
        if nested_attributes_association?(record_or_name_or_array)
          return fields_for_with_nested_attributes(record_or_name_or_array, args, block)
        else
          name = "#{object_name}#{index}[#{record_or_name_or_array}]"
        end
      when Array
        object = record_or_name_or_array.last
        name = "#{object_name}#{index}[#{ActionController::RecordIdentifier.singular_class_name(object)}]"
        args.unshift(object)
      else
        object = record_or_name_or_array
        name = "#{object_name}#{index}[#{ActionController::RecordIdentifier.singular_class_name(object)}]"
        args.unshift(object)
      end
      @template.fields_for(name, *args, &block)
    end
def fields_for ( record_or_name_or_array , * args , & block ) if options . has_key? ( :index ) index = "[#{options[:index]}]" elsif defined? ( @auto_index ) self . object_name = @object_name . to_s . sub ( / \[ \] $ / , "" ) index = "[#{@auto_index}]" else index = "" end args << { } unless args . last . is_a? ( Hash ) args . last . merge! ( @options . slice ( :no_label_for , :error_placement , :label_placement ) ) args . last [ :builder ] ||= options [ :builder ] || Labelify :: FormBuilder case record_or_name_or_array when String , Symbol if nested_attributes_association? ( record_or_name_or_array ) return fields_for_with_nested_attributes ( record_or_name_or_array , args , block ) else name = "#{object_name}#{index}[#{record_or_name_or_array}]" end when Array object = record_or_name_or_array . last name = "#{object_name}#{index}[#{ActionController::RecordIdentifier.singular_class_name(object)}]" args . unshift ( object ) else object = record_or_name_or_array name = "#{object_name}#{index}[#{ActionController::RecordIdentifier.singular_class_name(object)}]" args . unshift ( object ) end @template . fields_for ( name , * args , & block ) end
Taken directly from Rails fields_for implementation
Taken directly from Rails fields_for implementation
record_or_name_or_array
<not_specific>
args
<not_specific>
block
<not_specific>