Module: CoolNestedFormsHelper
- Defined in:
- app/helpers/cool_nested_forms_helper.rb
Instance Method Summary collapse
- #add_child_button(name, association, target, association_template = "", classes = "", child_template = "") ⇒ Object
- #new_fields_template(f, association, options = {}) ⇒ Object
- #remove_child_button(name, classes = "", inner_html = "<span>Remove</span>") ⇒ Object
Instance Method Details
#add_child_button(name, association, target, association_template = "", classes = "", child_template = "") ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 |
# File 'app/helpers/cool_nested_forms_helper.rb', line 29 def (name, association,target,association_template="",classes="",child_template="") association_template = association if association_template.blank? content_tag(:span,"<span>#{name}</span>".html_safe, :class => "add_child #{classes}", :style => "", :"data-association" => association, :"data-association-template" => association_template, :"data-child-template" => child_template, :id => "#{association_template}_button", :target => target) end |
#new_fields_template(f, association, options = {}) ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'app/helpers/cool_nested_forms_helper.rb', line 3 def new_fields_template(f,association,={}) [:object] ||= f.object.class.reflect_on_association(association).klass.new [:partial] ||= association.to_s.singularize [:template] ||= association.to_s [:child_template_options] ||= [] [:f] ||= f child_tmpl = "" tmpl = content_tag(:div,:id =>"#{[:template]}") do tmpl = f.fields_for(association,[:object], :child_index => "new_#{association}") do |b| if [:child_template_options].count > 0 [:child_template_options].each do |child| child_tmpl += new_fields_template(b,child[:association],child) end child_tmpl = child_tmpl.gsub( /\r?\n|\r/, ' ') end render(:partial=>[:partial],:locals =>{:f => b}) end end tmpl = tmpl.gsub( /\r?\n|\r/, ' ') script = "<script> var #{[:template]} = '#{tmpl.to_s}'; </script>" script += child_tmpl return script.html_safe end |
#remove_child_button(name, classes = "", inner_html = "<span>Remove</span>") ⇒ Object
40 41 42 43 44 |
# File 'app/helpers/cool_nested_forms_helper.rb', line 40 def (name, classes="", inner_html="<span>Remove</span>") content_tag(:div,inner_html.html_safe, :style => "", :class => "remove_child #{classes}") end |