ruby-on-rails – 在rails中使用多选列表
发布时间:2020-12-17 03:46:48 所属栏目:百科 来源:网络整理
导读:我正在尝试在Rails中创建一个多选列表框.我的观看代码是: div %=nested_form_for(@allocation) do|builder|% %=builder.label :song_id,"Pick a song" % %=builder.select :song_id,options_for_select( Song.all.collect {|s| [ [s.title,s.artist].join("
我正在尝试在Rails中创建一个多选列表框.我的观看代码是:
<div> <%=nested_form_for(@allocation) do|builder|%> <%=builder.label :song_id,"Pick a song" %> <%=builder.select :song_id,options_for_select( Song.all.collect {|s| [ [s.title,s.artist].join(" by "),s.id ] },{ include_blank: true,multiple: true,size: 5 }) %> <%=builder.submit "Add Song",class: "btn btn-large btn-primary" %> <% end %> </div> 目前我只有正常的单选择框,但我想将其转换为多选.任何指针都将非常感激.提前致谢 解决方法
这似乎适用于我的情况:
<%= builder.select( :song_id,options_for_select(@selections),{},{multiple: true,size: 10}) %> (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |