且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Ruby on Rails:相同形式的多个相同输入字段

更新时间:2023-10-06 14:13:46

它失败了,因为你上面得到的评估结果为具有 same name/id 的 html 字段,并且浏览器只会发布其中之一的价值.如果它们是不同的字段,那么您需要为它们提供唯一的名称/ID 或者您需要将它们创建为一个数组,例如:

It's failing because what you've got above evaluates to thee html field with the same name/id and the browser will only post the value for one of them. If they are different fields, then you need to give them unique names/ids or you need to create them as an array eg:

  <%= f.text_field_tag 'content_array[]' %>

或者,如果您希望这些成为一组帖子 - 您需要使用自定义表单添加多个子表单(每个帖子一个).

or, if you want these to be a set of posts - you'll need to add multiple sub-forms (one for each post) using a custom form.