我有一个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 -%>
答案 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