Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/57.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails Rails在另一个值的函数中形成__Ruby On Rails_Form For - Fatal编程技术网

Ruby on rails Rails在另一个值的函数中形成_

Ruby on rails Rails在另一个值的函数中形成_,ruby-on-rails,form-for,Ruby On Rails,Form For,我试图使用form_for helper来创建一个具有可变数量文本字段的表单 在一个页面上,我有一个包含两个值的表单: 这将把我带到另一个页面,在那里我希望有一个表单,将有一个可变数量的文本字段。字段的数量将为=到 我还没有添加正则表达式;我会做一次我相信这是最好的方法 如果是2,我想要一个如下的表单: 节是唯一可变的方面。 谢谢你的建议! 感谢阅读:D如果要向服务器传递数量可变的参数,最好将它们放入数组中。这样,控制器可以更轻松地处理它们。所以,用切面切面切面切面切面切面切面

我试图使用form_for helper来创建一个具有可变数量文本字段的表单

在一个页面上,我有一个包含两个值的表单:

这将把我带到另一个页面,在那里我希望有一个表单,将有一个可变数量的文本字段。字段的数量将为=到 我还没有添加正则表达式;我会做一次我相信这是最好的方法 如果是2,我想要一个如下的表单:

节是唯一可变的方面。 谢谢你的建议!
感谢阅读:D

如果要向服务器传递数量可变的参数,最好将它们放入数组中。这样,控制器可以更轻松地处理它们。所以,用切面切面切面切面切面切面切面切面切面切面切面切面切面切面切面切面切面切面切面切面切面切面切面切面切面切面切面切面切面切面切面切面切面切面切面切面切面切面切面切面切面切面切面切面切面切面切。您可以这样做:

<%= form_for :sections, url: sections_path do |f| %>  <p>
<p>
    <%= f.label :head_chord %><br>
    <%= f.text_field :head_chord %>
</p>
<%= @specs.sections.each_with_index do |section, index| %>
    <p>
        <%= label_tag "section_chord-#{index}", "section #{index}"%><br>
        <%= text_field_tag 'section_chord[]', nil, id: "section-chord-#{index}" %>
    </p>
<% end %>

这样rails就可以将section_chord视为一个数组。此代码未经测试,很可能需要一些清理,但它应该可以工作。

每个带有索引的\u都未定义。根据本地主机,如果我只想使用数字作为输入值,我应该做些什么?谢谢,对不起。我以为sections是一个活动记录数组。如果它只是一个数字,则将循环替换为:`要仅允许数字,请将文本\u field\u标记更改为number\u field\u tagThank,用于记录:您非常有帮助!
<p>
    <%= f.label :section_1_chord %><br>
    <%= f.text_field :section_1_chord %>
</p>

<p>
    <%= f.label :section_2_chord %><br>
    <%= f.text_field :section_2_chord %>
</p>

<p> 
    <%= f.label :foot_chord %>
    <%= f.text_field :foot_chord%>
</p>

<p> 
    <%= f.label :camber %>
    <%= f.text_field :camber %>
</p>

<p> 
    <%= f.label :draft_position %>
    <%= f.text_field :draft_position %>
</p>

<p> 
    <%= f.submit %>
</p>
<%= form_for :sections, url: sections_path do |f| %>  <p>
<p>
    <%= f.label :head_chord %><br>
    <%= f.text_field :head_chord %>
</p>
<%= @specs.sections.each_with_index do |section, index| %>
    <p>
        <%= label_tag "section_chord-#{index}", "section #{index}"%><br>
        <%= text_field_tag 'section_chord[]', nil, id: "section-chord-#{index}" %>
    </p>
<% end %>