2010-12-11 54 views

回答

6

据我所知,没有这样的辅助方法。

这是我会怎么做,在JS:

document.getElementById('someSelectBox').onchange = function() { 
    if(this.selectedIndex != this.options.length -1) return; 
    var new_name = prompt('Please enter a name'); 
    if(!new_name.length) return; 
    var textbox = document.createElement('input'); 
    textbox.value = new_name; 
    this.parentNode.appendChild(textbox); //parentNode is presumably the form 
} 

工作例如:http://jsfiddle.net/tCBqA/

2

签出以下视频@ RailsCasts.com。 Ryan Bates解释了如何创建嵌套表单,然后使用jQuery或Prototype动态添加和删除字段。这不是一个完美匹配你的问题,但应该让你朝着正确的方向前进。如果你得到了一些很好的代码,可以考虑将它发回给这个问题,让所有人都能看到。

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

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

+2

这似乎是不相关的业务方案的问题。 – 2012-05-13 04:53:49

+0

这是相关的。第二个链接覆盖它。 – ahnbizcad 2014-05-19 09:48:39