我有此代码,我想使用复选框而不是下拉菜单显示它。能做到吗?
<%= f.select :job_type_cont,[['Full Time','Full Time'],['Part Time','Part Time'],['Permanent','Permanent']],{:include_blank => 'All....'},class:"form-control",id:"bed_room" %>
答案 0 :(得分:0)
为此,需要一个复选框输入
首先,您需要在控制器中接收像数组一样的参数:
params.require(:model).permit(:others, job_type_cont: [])
然后,您应该像这样
<% job_type_conts = ['Full Time', 'Part Time', 'Permanent']%>
<% job_type_conts.each do |type| %>
# Edit: Check id and for of label and checkbox input
<%= f.check_box( :job_type_cont, { multiple: true, id: "#{type.gsub(" ","-")}"}, type ) %>
<%= f.label :job_type_cont, type, for: "#{type.gsub(" ","-")}" %>
<% end %>
您可以观看SophieDéziel的简单指南 Rails multiple checkboxes。