Display a checkbox list instead of multiple select

后端 未结 4 1355
失恋的感觉
失恋的感觉 2020-12-29 11:31

I have a model MyModel with a serialized attribute a, describing an array of symbols.

This code works :

<% form_for @my_         


        
4条回答
  •  臣服心动
    2020-12-29 11:36

    if you already have a select_tag

    <%= select_tag "filters", options_from_collection_for_select(filter_values, "id", "name", selected_ids), multiple:true, class:"form-control" %>
    

    and wants to replace it with check_box_tag, you will need to implement something like this:

    <%= check_box_tag "filters[]", value.id, selected_ids.include?(value.id), { :multiple => true} %> <%= value.name %>

    notice the ending brackets on the name which is needed to catch check box results in the same parameter.

    When I implemented this, the parameters were of the same format between the select_tag and the check_box_tag

提交回复
热议问题