Dynamically add and remove nested form fields

The form view

I follow outdated railscasts:

http://railscasts.com/episodes/197-nested-model-form-part-1

http://railscasts.com/episodes/197-nested-model-form-part-2

I tried to get the code to work in Rails 3, but unfortunately I only managed to temporarily disable the delete function (I violated the code elsewhere).

I also tried playing around with the "nested_form" stone, which seems to work fine in the squeaky clean environment created by the scaffold, but doesn't seem to work in my current project. In addition, I really want to understand what is happening behind the scenes, and not quickly use this stone, since this is the main part of my application.

Any advice on dynamically adding or removing nested fields using jQuery or some good helper methods would really be appreciated.

+4
source share
2 answers

Could you post the additional problem you had / had with the nested_form stone? It took me a little time to get it and run it due to my own incompetence, but it seems to work for me.

If you are looking for something more explicit code, you can simply create a helper method for jQuery clone () of the first element in your list, clear any inputs and jQuery append () to the end of the list of nested elements.

0
source

Ryan Bates saved the gem from his screencasts, just used it: https://github.com/ryanb/nested_form

-1
source

All Articles