开发者

Dynamically add and remove nested form fields

Dynamically add and remove nested form fields

I've been following along with the out-of-date railscasts:

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

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

I've been trying to make the code work in Rails 3 but unfortunately I have only been able to make the remove function work intermittently (I broke the code elsewhere).

I've also tried playing around with the 'nested_form' gem which seems to work great in a squeaky-clean scaffold-generated environment but doesn't seem to slot into my current project neatly. Furthermore, I really want to understand what's going on behind the scenes rather than get a quick gem-fix on this one as it is a core part开发者_JS百科 of my app.

Any tips on dynamically adding or removing nested fields with JQuery or some decent helper methods would be really, really appreciated.


Could you post any additional issue that you were/are having with the nested_form gem? It took me a bit to get it up and running due to my own incompetence, but it does seem to work for me.

If you are looking for something more explicit code-wise, you could just create a helper method to jQuery clone() the first element in your list, cleanse out any inputs, and jQuery append() it to the end of the list of nested elements.


Ryan Bates made a maintained gem from his screencasts, simply use it: https://github.com/ryanb/nested_form

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜