Called id for nil, which would mistakenly be 4 -- if you really wanted the id of nil, use object_id
这种问题如果是在一个事务中,你使用Customer.new的话,然后你又对customer进行一系列的操作,如下示例:
然后当你在save的时候就会报以上的
错误
customer = Customer.new(attr)
customer.channel_type = "101"
customer.channel_id = 101
customer.sales_id = 101
customer.save!
#此处会报错
此时的解决办法就是把new 改为 create然后就可以了
customer = Customer.create(attr)
customer.channel_type = "101"
customer.channel_id = 101
customer.sales_id = 101
customer.save!
如此代码为正确
具体原因尚未了解,希望高人解答!