Module: AjaxNestedForm::Helpers::ViewHelper
- Defined in:
- lib/ajax_nested_form/helpers/view_helper.rb
Instance Method Summary collapse
- #link_to_add_fields(name, f, association, container, position = "last", html_options = {}) ⇒ Object
- #link_to_remove_fields(name, f, container, html_options = {}) ⇒ Object
Instance Method Details
#link_to_add_fields(name, f, association, container, position = "last", html_options = {}) ⇒ Object
9 10 11 12 13 14 15 |
# File 'lib/ajax_nested_form/helpers/view_helper.rb', line 9 def link_to_add_fields(name, f, association, container, position = "last", = {}) new_object = f.object.class.reflect_on_association(association).klass.new fields = f.fields_for(association, new_object, :child_index => "new_#{association}") do |builder| render(association.to_s.singularize + "_fields", :f => builder) end link_to_function(name, "AjaxNestedForm.addFields(this, \"#{association}\", \"#{escape_javascript(fields)}\", \"#{container}\", \"#{position}\")".html_safe, ) end |
#link_to_remove_fields(name, f, container, html_options = {}) ⇒ Object
5 6 7 |
# File 'lib/ajax_nested_form/helpers/view_helper.rb', line 5 def link_to_remove_fields(name, f, container, = {}) f.hidden_field(:_destroy) + link_to_function(name, "AjaxNestedForm.removeFields(this, \"#{container}\")".html_safe, ) end |