Class: ActionView::Helpers::FormBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/nested_form_fields.rb

Instance Method Summary collapse

Instance Method Details



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/nested_form_fields.rb', line 26

def add_nested_fields_link association, text = nil, html_options = {}, &block
  html_options, text = text, nil if block_given? && text.is_a?(Hash)
  html_class = html_options.delete(:class) || {}
  html_data = html_options.delete(:data) || {}

  args = []
  args << (text || "Add #{association.to_s.singularize.humanize}") unless block_given?
  args << ''
  args << { class: "#{html_class.empty? ? '' : html_class} add_nested_fields_link",
            data: { association_path: association_path(association.to_s),
                    object_class: association.to_s.singularize }.merge(html_data)
          }.merge(html_options)

  @template.link_to *args, &block
end

#nested_fields_for(record_name, record_object = nil, fields_options = {}, &block) ⇒ Object



14
15
16
17
18
19
20
21
22
23
# File 'lib/nested_form_fields.rb', line 14

def nested_fields_for(record_name, record_object = nil, fields_options = {}, &block)
  fields_options, record_object = record_object, nil if record_object.is_a?(Hash) && record_object.extractable_options?
  fields_options[:builder] ||= options[:builder]
  fields_options[:parent_builder] = self
  fields_options[:wrapper_tag] ||= :fieldset
  fields_options[:wrapper_options] ||= {}
  fields_options[:namespace] = fields_options[:parent_builder].options[:namespace]

  return fields_for_has_many_association_with_template(record_name, record_object, fields_options, block)
end


42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/nested_form_fields.rb', line 42

def remove_nested_fields_link text = nil, html_options = {}, &block
  html_options, text = text, nil if block_given? && text.is_a?(Hash)
  html_class = html_options.delete(:class) || {}
  html_data = html_options.delete(:data) || {}

  args = []
  args << (text || 'x') unless block_given?
  args << ''
  args << { class: "#{html_class.empty? ? '' : html_class} remove_nested_fields_link",
            data: { delete_association_field_name: delete_association_field_name,
                    object_class: @object.class.name.underscore.downcase }.merge(html_data)
          }.merge(html_options)

  @template.link_to *args, &block
end