Module: NestedFieldsHelper

Defined in:
lib/generators/templates/nested_fields_helper.rb

Instance Method Summary collapse

Instance Method Details



7
8
9
10
11
12
13
14
15
# File 'lib/generators/templates/nested_fields_helper.rb', line 7

def link_to_new_child(f, association)
  object = f.object.class.reflect_on_association(association.to_sym).klass.new

  fields = f.fields_for(association, object, :child_index => "new_#{association.singularize}") do |builder|
    render("#{association.singularize}_fields", :f => builder)
  end

  link_to_function "Add #{association}", h("add_child_field('#{association}', 'new_#{association.singularize}', \"#{escape_javascript(fields)}\")")
end


3
4
5
# File 'lib/generators/templates/nested_fields_helper.rb', line 3

def link_to_remove_fields(name, f, container)
  f.hidden_field(:_destroy) + link_to_function(name, "remove_fields(this, '#{container}')")
end