我正在使用Rails表单。我知道在multiple: false
时如何选择保留在表单中(感谢此帖:rails erb form helper options_for_select :selected)但是当我multiple: true
时我遇到了问题,因为当你回去编辑。
编辑表格:
<%= p.label :basement %>
<%= p.select :basement, options_for_select(["Apartment", "Finished", "Partially finished", "Separate Entrance", "Unfinished", "Walk-out", "None"],selected: p.object.basement), {include_blank: false} ,{multiple: true} %>
<%= p.label :flooring %>
<%= p.select :flooring, options_for_select(["Bamboo","Carpet", "Engineered Hardwood", "Hardwood", "Laminate", "Marble"],selected: p.object.flooring), {include_blank: false} ,{multiple: true} %>
控制器:
...
def params
params.require(:property).permit({basement:[]},{flooring:[]})
end
任何人都可以帮助我理解我可能缺少什么才能让它发挥作用吗?
答案 0 :(得分:0)
最简单的方法是使用像所选的jquery库:https://harvesthq.github.io/chosen/或select2:https://select2.github.io/examples.html