我有表单的字段,想与select2
<%= f.collection_select :product_ids, Product.all,:id, :name ,{},{ class: 'p_ids', multiple: true} %>
我的js
$(document).ready(function () {
$(".p_ids").select2({
tags:true,
tokenSeparators: [",", " "]
});
});
我的参数
params.require(:cost).permit(:day, :amount, :description, :source, product_ids:[])
但我有
Product(#70204276011560) expected, got NilClass(#70204185305100)
记录
"cost"=>{"day"=>"15-10-2016", "amount"=>"100", "description"=>"test", "source"=>"products", "product_ids"=>["", "1", "2"]}
如何解决?
答案 0 :(得分:0)
我猜这个错误是由日志中product_ids数组的头部的空值发生的。
"product_ids"=>["", "1", "2"]
你可以通过include_hidden:false选项删除空值,如下所示。
<%= f.collection_select :product_ids, Product.all, :id, :name, { include_hidden: false }, { class: 'p_ids', multiple: true } %>
答案 1 :(得分:0)
fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(600/dpi, 300/dpi), dpi=dpi)
js部分就是那个
<%= f.select :product_ids, Product.all.order(:name).collect{|c| [ c.name, c.id] }, {include_blank: false }, id: 'p_ids_selection', multiple: true, class: 'multiple' %>