single table inheritance - Rails STI: Forbidding parent class initialization -
i have rails model book, sti-inherited models fiction , nonfiction
while book holds lot of common logic, i'd forbid creation of parent book model. wondering elegant method doing in rails - suggestions appreciated
you raise error in book's initializer
class book def initialize *args raise "can't create book" if self.class == book super # if it's not book, proceed activerecord initialization end end
Comments
Post a Comment