In Rails, how to handle multiple checked checkboxes, just split on the , or?

前端 未结 5 1003
遇见更好的自我
遇见更好的自我 2020-12-02 20:43

Curious what the \'rails way\' of handling the situation when a user checks multiple checkboxes (with the same name value), and it gets posted back to the controller.

<
5条回答
  •  囚心锁ツ
    2020-12-02 20:53

    In addition to Chuck Callebs answer, I realised that with sending an empty string instead of nil or false as unchecked value, Rails will understand to remove associated ids on an update action:

    <%= f.check_box :tag_ids, {multiple: true}, tag.id, '' %>

提交回复
热议问题