Class: ActionView::Helpers::FormBuilder
- Inherits:
-
Object
- Object
- ActionView::Helpers::FormBuilder
- Defined in:
- lib/nested_form_fields.rb
Instance Method Summary collapse
- #add_nested_fields_link(association, text = nil, html_options = {}, &block) ⇒ Object
- #nested_fields_for(record_name, record_object = nil, fields_options = {}, &block) ⇒ Object
- #remove_nested_fields_link(text = nil, html_options = {}, &block) ⇒ Object
Instance Method Details
#add_nested_fields_link(association, text = nil, html_options = {}, &block) ⇒ Object
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, = {}, &block , text = text, nil if block_given? && text.is_a?(Hash) html_class = .delete(:class) || {} html_data = .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() @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, = {}, &block) , record_object = record_object, nil if record_object.is_a?(Hash) && record_object. [:builder] ||= [:builder] [:parent_builder] = self [:wrapper_tag] ||= :fieldset [:wrapper_options] ||= {} [:namespace] = [:parent_builder].[:namespace] return fields_for_has_many_association_with_template(record_name, record_object, , block) end |
#remove_nested_fields_link(text = nil, html_options = {}, &block) ⇒ Object
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, = {}, &block , text = text, nil if block_given? && text.is_a?(Hash) html_class = .delete(:class) || {} html_data = .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() @template.link_to *args, &block end |