Module: AnafHabtm::ApplicationHelperMethods
- Defined in:
- lib/anaf_habtm/application_helper_methods.rb
Instance Method Summary collapse
- #add_child_link(name, child, form_builder, options = {}) ⇒ Object
- #new_child_fields(child, form_builder, options = {}) ⇒ Object
- #remove_child_link(name, form_builder) ⇒ Object
- #text_area_with_auto_complete(f, field, controller, opts = {}) ⇒ Object
- #tfwac(f, field, controller, opts = {}) ⇒ Object
Instance Method Details
#add_child_link(name, child, form_builder, options = {}) ⇒ Object
10 11 12 13 14 15 |
# File 'lib/anaf_habtm/application_helper_methods.rb', line 10 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, ={}, ={"href"=>"#", "class"=>"add-child-link", "data-class-name"=>child}) end |
#new_child_fields(child, form_builder, options = {}) ⇒ Object
17 18 19 20 21 22 23 24 |
# File 'lib/anaf_habtm/application_helper_methods.rb', line 17 def new_child_fields(child, form_builder, ={}) partial = [:partial] ||= child.underscore output = "" form_builder.fields_for(child.pluralize.to_sym, child.camelize.constantize.new, :child_index => "__#{child}_id__") do |f| output += render(:partial => partial, :locals => { :f => f }) end output end |
#remove_child_link(name, form_builder) ⇒ Object
3 4 5 6 7 8 |
# File 'lib/anaf_habtm/application_helper_methods.rb', line 3 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, ={}, ={"href"=>"#", "class"=>"remove-child-link", :tabindex=> "0"}) end |
#text_area_with_auto_complete(f, field, controller, opts = {}) ⇒ Object
32 33 34 35 36 |
# File 'lib/anaf_habtm/application_helper_methods.rb', line 32 def text_area_with_auto_complete(f, field, controller, opts={}) opts["data-auto-complete"]='ta' opts["data-auto-complete-url"]=eval("#{controller.to_s.underscore.tableize}_path(:format=>:json)") f.text_area field, opts end |
#tfwac(f, field, controller, opts = {}) ⇒ Object
26 27 28 29 30 |
# File 'lib/anaf_habtm/application_helper_methods.rb', line 26 def tfwac(f, field, controller, opts={}) opts["data-auto-complete"]='tf' opts["data-auto-complete-url"]=eval("#{controller.to_s.underscore.tableize}_path(:format=>:json)") f.text_field field, opts end |