Class: ActionView::Helpers::FormBuilder
- Inherits:
-
Object
- Object
- ActionView::Helpers::FormBuilder
- Defined in:
- lib/nested_fields_rails/form_builder.rb
Instance Method Summary collapse
- #default_fields_for_nested_model ⇒ Object
- #fields_for_nested_model(name, object, options, block) ⇒ Object
- #index_nested_fields(attribute_name) ⇒ Object
- #link_to_add_nested_fields(*args, &block) ⇒ Object
- #link_to_down_nested_fields(*args, &block) ⇒ Object
- #link_to_remove_nested_fields(*args, &block) ⇒ Object
- #link_to_up_nested_fields(*args, &block) ⇒ Object
- #nested_fields_for(association_name, record_object = nil, fields_options = {}, &block) ⇒ Object
Instance Method Details
#default_fields_for_nested_model ⇒ Object
45 |
# File 'lib/nested_fields_rails/form_builder.rb', line 45 alias default_fields_for_nested_model fields_for_nested_model |
#fields_for_nested_model(name, object, options, block) ⇒ Object
46 47 48 49 50 51 52 53 54 |
# File 'lib/nested_fields_rails/form_builder.rb', line 46 def fields_for_nested_model(name, object, , block) tag = [:element_wrapper] || ([:wrapper] && [:wrapper].to_sym == :table ? :tr : nil) || :div html_attributes = { :class => 'fields', 'data-object-id' => [:child_index] || object.object_id, :style => object._destroy ? 'display: none;' : '' } @template.content_tag(tag, default_fields_for_nested_model(name, object, , block), html_attributes) end |
#index_nested_fields(attribute_name) ⇒ Object
26 27 28 |
# File 'lib/nested_fields_rails/form_builder.rb', line 26 def index_nested_fields(attribute_name) hidden_field attribute_name, :class => 'index' end |
#link_to_add_nested_fields(*args, &block) ⇒ Object
4 5 6 7 8 9 10 11 12 |
# File 'lib/nested_fields_rails/form_builder.rb', line 4 def link_to_add_nested_fields(*args, &block) = args..symbolize_keys association = args.pop [:class] = [[:class], 'add-nested-fields'].compact.join(' ') ['data-association'] = association args << (.delete(:href) || 'javascript:void(0)') args << @template.link_to(*args, &block) end |
#link_to_down_nested_fields(*args, &block) ⇒ Object
22 23 24 |
# File 'lib/nested_fields_rails/form_builder.rb', line 22 def link_to_down_nested_fields(*args, &block) link_to_action_nested_fields(:down, *args, &block) end |
#link_to_remove_nested_fields(*args, &block) ⇒ Object
14 15 16 |
# File 'lib/nested_fields_rails/form_builder.rb', line 14 def link_to_remove_nested_fields(*args, &block) (hidden_field(:_destroy, :class => 'destroy') << link_to_action_nested_fields(:remove, *args, &block)).html_safe end |
#link_to_up_nested_fields(*args, &block) ⇒ Object
18 19 20 |
# File 'lib/nested_fields_rails/form_builder.rb', line 18 def link_to_up_nested_fields(*args, &block) link_to_action_nested_fields(:up, *args, &block) end |
#nested_fields_for(association_name, record_object = nil, fields_options = {}, &block) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/nested_fields_rails/form_builder.rb', line 30 def nested_fields_for(association_name, record_object = nil, = {}, &block) collection_wrapper = [:collection_wrapper] || ([:wrapper] && [:wrapper].to_sym == :table ? :tbody : nil) || :div element_wrapper = [:element_wrapper] || ([:wrapper] && [:wrapper].to_sym == :table ? :tr : nil) || :div fields_block = block || Proc.new { |fields| @template.render(:partial => "#{association_name.to_s.singularize}_fields", :locals => {:f => fields}) } fields = @template.content_tag(collection_wrapper, fields_for(association_name, record_object, , &fields_block), :id => association_name, :class => 'nested-fields') model_object = object.class.reflect_on_association(association_name).klass.new template = fields_for(association_name, model_object, :element_wrapper => element_wrapper, :child_index => "new_#{association_name}", &fields_block) = {:id => "#{association_name}_fields_template", :type => 'text/x-jquery-tmpl'} fields_template = @template.content_tag(:script, template, ) fields + fields_template end |