您可以使用空数组设置输入的名称:
number_field_tag 'problem[restrictions][1][]', 0
number_field_tag 'problem[restrictions][1][]', 5
然后在您的 ProblemController 中,您应该收到如下参数:
params[:problem][:restrictions][1]
# => contains the 2 values serialized as array
所以完整的形式是:
X <
<%= number_field_tag 'problem[restrictions][0]', 0 %>
<%= number_field_tag 'problem[restrictions][1][]', 0 %>
<= X <=
<%= number_field_tag 'problem[restrictions][1][]', 5 %>
<%= number_field_tag 'problem[restrictions][2]', 0 %>
< X
你最终会得到以下参数:
params = {
problem: { #all the Problem attributes filled in the form },
restrictions:
[
<value of first input>,
[<value of second input>, <value of third input>],
<value of fourth input>
]
}