我正在使用active_record-acts_as gem来实现多表继承。我的情景:
class Vehicle < ActiveRecord::Base
actable
before_destroy :some_validations
def some_validations
if some_condition
errors.add(:base, "cant be deleted")
return false
else
return true
endif
end
end
class Plane < ActiveRecord::Base
acts_as :Vehicle
end
class Train < ActiveRecord::Base
acts_as :Vehicle
end
如果我执行:
p = Plane.first
p.destroy
按预期返回false
,但执行时:
p.errors.messages
我明白了:
{}
如何在调用child.errors时获取父级错误?