Rails STI - Prevent base class from instantiation

前端 未结 6 893
陌清茗
陌清茗 2021-01-01 11:06

Is there any way in a Rails STI situation to throw an error when the base class is Instantiated? Overriding initialize will do it but then that gets trickled down to the sub

6条回答
  •  时光说笑
    2021-01-01 11:36

    In the initialize function check that the class is the STI base class.

    Though the question is why would you exactly want to do this? It seems more likely that trying out a different design might help you more.

提交回复
热议问题