i know there are some threads about the railscast nested forms... and that link_to_add_fields is not working proper in rails 4 anymore, because of the change about the unobstrusive js. can someone help me to understand and tell me what i do have to change in order to get my nested form working? i´m trying to "rebuild":complex form but he uses rails 3 and i´m rails 4. i do get the following error:
undefined method `link_to_function' for
in _form.html.erb:
<%= link_to_add_fields("Add a Contact", f, :contacts, :class => "btn btn-primary", :title => "Add a new Contact") %>
my application_helper.rb
def link_to_add_fields(name, f, association, options = {})
new_object = f.object.class.reflect_on_association(association).klass.new
fields = f.fields_for(association, new_object, :child_index => "new_#{ association }", :onsubmit => "return $(this.)validate();") do |builder|
render(association.to_s.singularize + "_fields", :f => builder)
end
link_to_function(name, "add_fields(this, \"#{ association }\", \"#{ escape_javascript(fields) }\")", options)
end end
thanks!