def link_to_add_association(*args, &block)
      if block_given?
        link_to_add_association(capture(&block), *args)
      elsif args.first.respond_to?(:object)
        association = args.second
        name = I18n.translate("cocoon.#{association}.add", default: I18n.translate('cocoon.defaults.add'))

        link_to_add_association(name, *args)
      else
        name, f, association, html_options = *args
        html_options ||= {}

        render_options   = html_options.delete(:render_options)
        render_options ||= {}
        override_partial = html_options.delete(:partial)
        wrap_object = html_options.delete(:wrap_object)
        force_non_association_create = html_options.delete(:force_non_association_create) || false
        form_parameter_name = html_options.delete(:form_name) || 'f'
        count = html_options.delete(:count).to_i

        html_options[:class] = [html_options[:class], "add_fields"].compact.join(' ')
        html_options[:'data-association'] = association.to_s.singularize
        html_options[:'data-associations'] = association.to_s.pluralize

        new_object = create_object(f, association, force_non_association_create)
        new_object = wrap_object.call(new_object) if wrap_object.respond_to?(:call)

        html_options[:'data-association-insertion-template'] = CGI.escapeHTML(render_association(association, f, new_object, form_parameter_name, render_options, override_partial).to_str).html_safe

        html_options[:'data-count'] = count if count > 0

        link_to(name, '#', html_options)
      end
    end
def link_to_add_association(*args, &block)
      if block_given?
        link_to_add_association(capture(&block), *args)
      elsif args.first.respond_to?(:object)
        association = args.second
        name = I18n.translate("cocoon.#{association}.add", default: I18n.translate('cocoon.defaults.add'))

        link_to_add_association(name, *args)
      else
        name, f, association, html_options = *args
        html_options ||= {}

        render_options   = html_options.delete(:render_options)
        render_options ||= {}
        override_partial = html_options.delete(:partial)
        wrap_object = html_options.delete(:wrap_object)
        force_non_association_create = html_options.delete(:force_non_association_create) || false
        form_parameter_name = html_options.delete(:form_name) || 'f'
        count = html_options.delete(:count).to_i

        html_options[:class] = [html_options[:class], "add_fields"].compact.join(' ')
        html_options[:'data-association'] = association.to_s.singularize
        html_options[:'data-associations'] = association.to_s.pluralize

        new_object = create_object(f, association, force_non_association_create)
        new_object = wrap_object.call(new_object) if wrap_object.respond_to?(:call)

        html_options[:'data-association-insertion-template'] = CGI.escapeHTML(render_association(association, f, new_object, form_parameter_name, render_options, override_partial).to_str).html_safe

        html_options[:'data-count'] = count if count > 0

        link_to(name, '#', html_options)
      end
    end
shows a link that will allow to dynamically add a new associated object.

 - *name* :         the text to show in the link
 - *f* :            the form this should come in (the formtastic form)
 - *association* :  the associated objects, e.g. :tasks, this should be the name of the <tt>has_many</tt> relation.
 - *html_options*:  html options to be passed to <tt>link_to</tt> (see <tt>link_to</tt>)
          - *:render_options* : options passed to `simple_fields_for, semantic_fields_for or fields_for`
              - *:locals*     : the locals hash in the :render_options is handed to the partial
          - *:partial*        : explicitly override the default partial name
          - *:wrap_object*    : a proc that will allow to wrap your object, especially suited when using
                                decorators, or if you want special initialisation
          - *:form_name*      : the parameter for the form in the nested form partial. Default `f`.
          - *:count*          : Count of how many objects will be added on a single click. Default `1`.
 - *&block*:        see <tt>link_to</tt>