新手问题 怎样在 form 中提交将多个 select 的值组合成一个数组提交

gechentuo · March 31, 2014 · Last by hz_qiuyuanxin replied at April 02, 2014 · 3840 hits

我的问题是这样的:

我需要在一个 form 表单中 将多个 select 的值放在同一个数组中,提交给 controller,

下面是我的代码:

<%= f.label :teacher_author %><br>
<% teachers_array = Teacher.all.map { |t| [t.name,t.id]  }%>
 <%= f.select :teacher_ids,options_for_select(teachers_array) %>
<%= f.select :teacher_ids,options_for_select(teachers_array) %>

问题是,两个 select 的值,只有一个能在请求中出现,好像给覆盖掉了

请教大家

首先,你要明白,form 表单提交里,是怎么提交数组的?

<input type="hidden" name="coins[]" value="50" />
<input type="hidden" name="coins[]" value="40" />
<input type="hidden" name="coins[]" value="30" />
<input type="hidden" name="coins[]" value="20" />
<input type="hidden" name="coins[]" value="10" />

其次,Rails Document 已经写清楚了

最后,你不懂你还可以 google

You need to Sign in before reply, if you don't have an account, please Sign up first.