表单标记只有一个值传递而不是多个

时间:2014-01-31 14:38:36

标签: ruby-on-rails ruby ruby-on-rails-3 forms

我有一个form_tag形式,其中包含两个下拉框。当我提交表单时,两个字段ID都没有通过我不知道我在哪里做错了...

<%= form_tag '/daily_report' do -%>
<label>Search</label>
<%= select_tag "id", options_from_collection_for_select(User.all, "id", "firstname",:selected => @s) %>
<%= select_tag "id", options_from_collection_for_select(Project.all, "id", "name",:selected => @s) %>
<%= submit_tag "Search", :name => nil %>
<% end -%>

1 个答案:

答案 0 :(得分:1)

如果您使用相同的名称,将覆盖这些值,您将只获得一个结果。所以改变名称并使其不同。

<%= select_tag "users", options_from_collection_for_select(User.all, "id", "firstname",:selected => @s) %>
<%= select_tag "projects", options_from_collection_for_select(Project.all, "id", "name",:selected => @s) %>

您现在可以使用名称:users:projects

进行访问