Module: ValueObjects::ActionView::Cocoon

Defined in:
lib/value_objects/action_view/cocoon.rb

Instance Method Summary collapse

Instance Method Details



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][_]")
  (:a, name, html_options) + dummy_input
end


27
28
29
30
31
32
33
34
35
# File 'lib/value_objects/action_view/cocoon.rb', line 27

def link_to_remove_nested_value(name, html_options = {}, &block)
  wrapper_class = html_options.delete(:wrapper_class)

  html_options[:class] = [html_options[:class], 'remove_fields dynamic'].compact.join(' ')
  html_options[:'data-wrapper-class'] = wrapper_class if wrapper_class

  name = capture(&block) if block_given?
  (:a, name, html_options)
end