为选择标记设置多选

时间:2016-07-19 20:54:15

标签: ruby-on-rails ruby-on-rails-4

我有一个select标签,我通过循环记录和手动创建选项来生成。这是代码:

    <%= f.select (:book_id_eq_any) do %>
      <%= content_tag(:option, "Choose your option", value: "", disabled: '', selected: '') %>
      <% @books.each do |book| %>
        <%= content_tag(:option, book.book_title, value: book.id) %>
      <% end %>
   <% end %>

当我添加{multiple:true}时,它不起作用。任何人都可以给我一些暗示。感谢

1 个答案:

答案 0 :(得分:0)

只需使用内置的选择表单助手:

<%= f.collection_select :book_id_eq_any, @books, :id, :book_title, { include_blank: "Choose your option" }, { multiple: true } %>