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

user interface - Python attempting to create a simple gui, getting "AttributeError: 'MainMenu' object has no attribute 'intro_screen'" -

jquery - Common JavaScript snippet to share files on Google Drive, Dropbox, Box.net or SkyDrive -

Android Gson.fromJson error -