我正在尝试在表单中创建一组动态输入,只从一个开始,您可以使用添加/删除按钮添加或删除它们。然后在提交表单时,它将输入的值转换为哈希值,然后将该哈希值转换为字符串以进行存储。我真的不知道从哪里开始。所以任何提示都会有所帮助。
如果使用javascript会有帮助,我可以走那条路,但我不知道如何制作javascript和ruby说话。
答案 0 :(得分:2)
Depending on your use-case, there are a few options you might want to use. Since you've tagged this with rails
, I'm assuming you have access to JQuery. Here's one (very simple) example of how you might go about adding fields to the page dynamically using it:
https://jsfiddle.net/3Lyvw0jm/
If you plan on storing these fields in one of your models, you may want to take a look at implementing nested attributes.