首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

Called id for nil, which would mistakenly be 4 异常解决之一

2012-12-20 
Called id for nil, which would mistakenly be 4 错误解决之一Called id for nil, which would mistakenl

Called id for nil, which would mistakenly be 4 错误解决之一
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!
  如此代码为正确

具体原因尚未了解,希望高人解答!

热点排行