= form.collection_check_boxes :category_ids, Item::Category.all, :id, :name, checked: "#{@search.try(:category_ids)}"
返回
"[\"3\", \"\"]"
但它应该产生
["3", ""]
为什么会这样?
@search.try(:category_ids) is ["3", ""]
答案 0 :(得分:5)
您应该删除引号,这是不必要的
= form.collection_check_boxes :category_ids, Item::Category.all, :id, :name, checked: @search.try(:category_ids)