Sha256: 1885661bfdd879cbbf6fb089abcb2d4c6d890d1dd2d9a07f27920bcd9bc29504

Contents?: true

Size: 715 Bytes

Versions: 7

Compression:

Stored size: 715 Bytes

Contents

module ApplicationHelperMethods
  def remove_child_link(name, form_builder)
    form_builder.hidden_field(:_destroy) + link_to_function(name, "remove_child(this)", :tabindex => "0")
  end

  def add_child_link(name, child, form_builder)
    # puts "||#{form_builder}||"
    fields = escape_javascript(new_child_fields(child, form_builder))
    link_to_function(name, h("add_child(this, \"#{child}\", \"#{fields}\")"))
  end

  def new_child_fields(child, form_builder)
    output = ""
    form_builder.fields_for(child.pluralize.to_sym, child.camelize.constantize.new, :child_index => 'NEW_RECORD') do |f|
      output += render(:partial => child.underscore, :locals => { :f => f })
    end
    output
  end  
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
anaf_habtm-0.0.7 lib/application_helper_methods.rb
anaf_habtm-0.0.6 lib/application_helper_methods.rb
anaf_habtm-0.0.5 lib/application_helper_methods.rb
anaf_habtm-0.0.4 lib/application_helper_methods.rb
anaf_habtm-0.0.3 lib/application_helper_methods.rb
anaf_habtm-0.0.2 lib/application_helper_methods.rb
anaf_habtm-0.0.1 lib/application_helper_methods.rb