获取Options_for_select要保留的多个选定项目

时间:2016-03-11 20:35:15

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

我正在使用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

任何人都可以帮助我理解我可能缺少什么才能让它发挥作用吗?

1 个答案:

答案 0 :(得分:0)

最简单的方法是使用像所选的jquery库:https://harvesthq.github.io/chosen/或select2:https://select2.github.io/examples.html