Adding dynamic fields to nested form through AJAX
ajax, nested-forms, railscasts, ruby-on-rails
Solution
I don't have a pro account on Railscasts either, but sometimes it is a good idea to have a look at Ryan's Github account. Oftentimes he develops gems to stuff he covered in his episodes. There you will find this awesome nested_form gem, which does exactly what you want.
Of course you can reinvent the wheel, but I think it is much easier and faster to use Ryan's gem. The documentation explains perfectly how to use it. Have fun!
Problem
I've been watching and reproducing these railscasts on my app: 196-nested-model-form-part-1 and 197-nested-model-form-part-2. I do not yet have a pro account so i can't watch the revised episode. I'm developing under rails4 (edge) and `link_to_function` has been deprecated in favor of unobstrusive JS (which is great). I'll keep the example of the above railscasts (i.e. survey/question). What i'd like to do is to use the question's partial through unobstrusive javascript and i just don't know how and where i should do this. I was thinking of two ways to do so : - First way would be to add in my `app/assets/javascripts` a file `surveys.js` with the function `add_question` but i don't see how i could use my partial from here. - Other way would be to create a new action in my `SurveyController` that would respond using the question partial but i'm bothered by the fact of having an action specific to questions in my survey controller. I can't help to think there must be a better way to do this.