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

Popular posts from this blog

java - Multi-Label Document Classification -

php - Dynamic url re-writing using htaccess -

python - How to create a legend for 3D bar in matplotlib? -