Rails多表继承:从子

时间:2016-02-16 15:12:57

标签: ruby-on-rails inheritance

我正在使用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时获取父级错误?

0 个答案:

没有答案