module AnafHabtm module ApplicationHelperMethods def remove_child_link(name, form_builder) value = form_builder.object.new_record? ? "1" : "false" klass = form_builder.object.class.name.underscore form_builder.hidden_field(:_destroy, {:value=>value, "data-remove"=>klass}) + link_to(name, options={}, html_options={"href"=>"#", "class"=>"remove-child-link", :tabindex=> "0"}) end def add_child_link(name, child, form_builder) # puts "||#{form_builder}||" new_form = new_child_fields(child, form_builder) raw(content_tag(:div, new_form, {:id=>"#{child}_template", :class=>"form-template"}, escape=false))+ link_to(name, options={}, html_options={"href"=>"#", "class"=>"add-child-link", "data-class-name"=>child}) end def new_child_fields(child, form_builder) output = "" form_builder.fields_for(child.pluralize.to_sym, child.camelize.constantize.new, :child_index => "__#{child}_id__") do |f| output += render(:partial => child.underscore, :locals => { :f => f }) end output end def tfwac(f, field, controller) f.text_field field, "data-auto-complete"=>true, "data-auto-complete-url"=> eval("#{controller.to_s.underscore.tableize}_path(:format=>:json)") end end end