如何 post 具有多个 select 表单字段的 ID 集合 phoenix_html

How to post a collection of ids with multiple select form field with phoenix_html

我正在尝试让多个 select 与 phoenix_html 表单助手一起工作

<%= select f, :challenge_ids, ["foo": "1","bar": "2","baz": "3"], class: "form-control", multiple: ""  %>

但只有最后一个 selected 项目的 ID 被发送到参数

中的服务器
%{"challenge_ids" => "3", "content" => "", "name" => ""}

我也曾尝试将 :challeng_ids 更改为 :"challenge_ids[]" 以尝试为多个 select 标签获得类似于 rails 输出的内容,但这并没有成功有什么区别

Aaron 的 PR for adding multiple_select was merged into phoenix_html. Here's an example from the docs for multiple_select/4 以防其他人遇到同样的问题:

# Assuming form contains a User model
multiple_select(form, :roles, ["Admin": 1, "Power User": 2])
#=> <select id="user_roles" name="user[roles][]">
    <option value="1">Admin</option>
    <option value="2">Power User</option>
    </select>