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
# File 'lib/nested_form_fields.rb', line 26

def add_nested_fields_link association, text = nil, html_options = {}
  html_class = html_options.delete(:class) || {}
  html_data = html_options.delete(:data) || {}
  @template.link_to text || "Add #{association.to_s.singularize.humanize}", '', {
                    class: "#{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)
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


35
36
37
38
39
40
41
42
# File 'lib/nested_form_fields.rb', line 35

def remove_nested_fields_link text = nil, html_options = {}
  html_class = html_options.delete(:class) || {}
  html_data = html_options.delete(:data) || {}
  @template.link_to text || 'x', '', {
                    class: "#{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)
end