我正在做的升级是
- Ruby 2.6
- MongoDB 3.6
- Mongoid从5.0到7.1
- Rails从4.2到5.2
我有一个回调,在一定条件下停止未来的回调。现在我必须使用throw(:abort)
来停止回调并阻止save
操作,Mongoid将抛出:
Mongoid::Errors::Callback:
message:
Calling save! on Survey resulted in a false return from a callback.
summary:
If a before callback returns false when using Document.create!, Document#save!, or Document#update_attributes! this error will get raised since the document did not actually get saved.
resolution:
Double check all before callbacks to make sure they are not unintentionally returning false.
这是有问题的。我们甚至不期望一个错误消息,这是记录,我们继续前进。我们只想让record.save
返回false
。如何从Mongoid中抑制这个异常?
1条答案
按热度按时间t1qtbnec1#
问题是我抛出了false,同时也返回了false。throw(:abort)。