Rails STI validation inheritance

拟墨画扇 提交于 2019-12-12 18:17:39

问题


I have STI models in my Rails application. The ancestor model has validations with the validates_... methods which are working fine.

But I have custom validations as well, and I would like to add more different custom validations in the descendants. These custom validations would depend on the class.

If I write

class DescendantA < Ancestor

  protected
    def validate
      # ...
    end
end

It simply overwrites the original validations, so I loose the original inherited validations.

Is there a convention to do this in Rails?


回答1:


Would it not be sufficient to add super at the end of the validate method in the child, so that the parent's validate method would also be called?



来源:https://stackoverflow.com/questions/4660159/rails-sti-validation-inheritance

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!