view
<% @roles.each do |role| %> <%= check_box_tag ‘roles[]‘, role.id%> <%= label_tag role.name %> <% end %>
生成HTML页面效果
<input type="checkbox" value="1" name="roles[]" id="roles_"> <label for="SuperAdmin">Superadmin</label> <input type="checkbox" value="2" name="roles[]" id="roles_"> <label for="Teacher">Teacher</label> <input type="checkbox" value="3" name="roles[]" id="roles_"> <label for="Student">Student</label>
controller获得信息
"roles"=>["2", "3"] #params[:roles]
Rails多个复选框--check_box_tag,布布扣,bubuko.com
原文:http://www.cnblogs.com/zs-note/p/3796357.html