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
时间: 2024-10-12 12:27:48