我想要一個select2標籤下拉列表,其中我可以選擇多個現有標籤並添加新標籤。Rails與select2(和simple_form)一起作爲標記的開始
我已經嘗試了很多不同的方法,我要麼不會使select2框工作,要麼只傳遞一個值(最後一個)。
這是最接近我得到了(通過最後一個值):
<%= f.input :tag_list, collection: @model.tags.map { |t| t.name }, input_html: { :style=> 'width: 300px', class: "taggable", data: { placeholder: "Tags" }} %>
你的關於tag_list []的觀點對我來說至關重要 - 標籤被提交爲一個字符串數組,如[「a」,「b」,「c」],而不是像「a,b,c」 –