mercredi 17 janvier 2018

Updating model after unchecking all checkboxes

I have a form to create a device that selects which users will have a device. So one of the fields are with checkboxes selecting the users:

<% User.all.each do |user| %>
  <label class="checkbox-inline">
    <%= f.check_box :user_ids, {:multiple => true}, user.id, nil  %> <%= user.name %>
  </label>
<% end >

When editing, if I check anyone of the boxes, the param :user_ids is passed to the controller with the other parameters. But if I do not check any box, in case I do not want any user to be linked to a device at the moment, the param :user_ids does not exist when the parameters are passed to the controller.

What do I do to make "user_ids"=>[] as a parameter when none checkbox is checked?




Aucun commentaire:

Enregistrer un commentaire