在Rails,我怎么能找出导致一个.save()失败,不是验证错误等? [英] In rails, how can I find out what caused a .save() to fail, other than validation errors?
问题描述
我有一个ActiveRecord的模式,将返回真
从是否有效?
(和.errors是空的),但在返回假
从保存()
。如果该模型实例是有效的,我怎么能找出什么导致保存失败?
I have an ActiveRecord model which is returning true
from valid?
(and .errors is empty), but is returning false
from save()
. If the model instance is valid, how can I find out what's causing the save to fail?
推荐答案
检查所有的回调。
我有这样一个问题,我已经和after_validate方法是失败后,我做了一堆改变模式。该模型是有效的,但after_validate返航假的,所以如果我用 model.valid
它说真的,但如果我救它给了我验证错误(通过传递从after_validate回调)。这是不可思议。
I had a problem like this where I had and "after_validate" method that was failing after I had made a bunch of changes to the model. The model was valid but the "after_validate" was returning false, so if I used model.valid
it said true, but then if I saved it gave me validation errors (passed through from the after_validate callback). It was weird.
查看应用程序的跟踪,你应该能够看到一行code为提高例外。
Look at the application trace and you should be able to see what line of code is raising the exception.
这篇关于在Rails,我怎么能找出导致一个.save()失败,不是验证错误等?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!