8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
|
# File 'lib/value_objects/action_view/cocoon.rb', line 8
def link_to_add_nested_value(name, f, attribute, value_class, html_options = {}, &block)
render_options = html_options.delete(:render_options) || {}
partial = html_options.delete(:partial)
wrap_object = html_options.delete(:wrap_object)
form_name = html_options.delete(:form_name) || 'f'
count = html_options.delete(:count).to_i
new_object = value_class.new
new_object = wrap_object.call(new_object) if wrap_object
html_options[:class] = [html_options[:class], 'add_fields'].compact.join(' ')
html_options[:'data-association'] = attribute
html_options[:'data-association-insertion-template'] = CGI.escapeHTML(render_association(attribute, f, new_object, form_name, render_options, partial)).html_safe
html_options[:'data-count'] = count if count > 0
name = capture(&block) if block_given?
dummy_input = tag(:input, type: 'hidden', name: "#{f.object_name}[#{attribute}_attributes][-1][_]")
content_tag(:a, name, html_options) + dummy_input
end
|