使用select_tag的多个记录

时间:2010-04-17 05:41:06

标签: ruby-on-rails html-select

更新:清除混淆:通过多条记录,我指的是同时有多个人。每个选民都有自己的select__tag,这就是我想把ID作为哈希传递的原因。

我正在尝试显示多条记录,每条记录都显示自己的选择框。我想提交此表单并传递一个哈希,将Add.id函数作为哈希的键,并将选择框选项作为哈希中的信息传递。我怎么能修复我的代码?这是否可以使用select_tag方法?

<%= form_tag yardsign_adds_path, :method => :post do %>
<%= select_tag "support_code[]",
            options_for_select([[ "1 - Strong Supporter", add.id ], 
         [ "2 - Likely Voter" ],
         [ "3 - Undecided" ],
         [ "4 - Likely Opposed" ],
         [ "5 - Strongly Opposed" ]]) %>
<%= submit_tag "Update" %>
<% end %>

当前终端输出:

Started POST "/adds/yardsign" for 127.0.0.1 at 2010-04-17 01:36:03
  Processing by AddsController#yardsign as HTML
  Parameters: {"commit"=>"Update", "authenticity_token"=>"VQ2jVfzHI7pB+87lQa9NWqvUK3zwJWiJE7CwAnIewiw=", "support_code"=>["1", "3 - Undecided", "3 - Undecided"]}

1 个答案:

答案 0 :(得分:0)

从小问题我得到你的问题我假设你希望用户能够从选择列表中选择多个选项参考下面的代码(请忽略,如果你想要别的东西)

<%= select_tag "support_code[]", :multiple=>true
            options_for_select([[ "1 - Strong Supporter", add.id ], 
         [ "2 - Likely Voter" ],
         [ "3 - Undecided" ],
         [ "4 - Likely Opposed" ],
         [ "5 - Strongly Opposed" ]]) %>