Class: SimpleNestedForm::Builder
- Inherits:
-
SimpleForm::FormBuilder
- Object
- SimpleForm::FormBuilder
- SimpleNestedForm::Builder
- Defined in:
- lib/simple_nested_form/builder.rb
Instance Method Summary collapse
- #fields_for(record_or_name_or_array, *args, &block) ⇒ Object
- #fields_for_nested_model(name, association, args, block) ⇒ Object
- #fields_for_with_nested_attributes(association, *args, block) ⇒ Object
- #link_to_add(*args, &block) ⇒ Object
- #link_to_remove(*args, &block) ⇒ Object
Instance Method Details
#fields_for(record_or_name_or_array, *args, &block) ⇒ Object
52 53 54 55 56 57 |
# File 'lib/simple_nested_form/builder.rb', line 52 def fields_for(record_or_name_or_array, *args, &block) = args. [:builder] = SimpleNestedForm::Builder super(record_or_name_or_array, *(args << ), &block) end |
#fields_for_nested_model(name, association, args, block) ⇒ Object
64 65 66 67 68 |
# File 'lib/simple_nested_form/builder.rb', line 64 def fields_for_nested_model(name, association, args, block) content_tag :div, :class => "fields #{association.class.model_name.human.downcase}" do super end end |
#fields_for_with_nested_attributes(association, *args, block) ⇒ Object
59 60 61 62 |
# File 'lib/simple_nested_form/builder.rb', line 59 def fields_for_with_nested_attributes(association, *args, block) nested_fields[association] = block super end |
#link_to_add(*args, &block) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/simple_nested_form/builder.rb', line 7 def link_to_add(*args, &block) if block_given? association = args.first = args.second || {} else name = args.first association = args.second = args.third || {} end .merge!(:"data-association" => association) [:"data-limit"] = .delete(:limit) after_nested_form(association) do model_object = object.class.reflect_on_association(association).klass.new content_tag :div, :id => "#{association}_fields_blueprint", :style => "display: none" do fields_for(association, model_object, :child_index => "new_#{association}", &nested_fields[association]) end end if block_given? link_to(capture(&block), "javascript:void(0)", ) else link_to(name, "javascript:void(0)", ) end end |
#link_to_remove(*args, &block) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/simple_nested_form/builder.rb', line 35 def link_to_remove(*args, &block) if block_given? = args.first || {} else name = args.first = args.second || {} end .merge!(:"data-remove-association" => 1) hidden_field(:_destroy) + if block_given? link_to(capture(&block), "javascript:void(0)", ) else link_to(name, "javascript:void(0)", ) end end |