Single Table Inheritance and Validations

You need to create an instance of the actual class. Since you’re creating it on Asset, the validations won’t fire.

You’ll need

  1. Determine what type to create and create it dynamically.

    asset_type = params[:asset][:class_name]

    do something here to restrict what type of asset you’re dealing with… we don’t want them hacking

    your system because the next line instantiates a class based off of the string!

    @asset = asset_type.constantitze.new

Or

  1. Put all validations on Asset and then run them conditionally with the :if option.

    validates_presense_of :description, :if=> :is_a_document?

    def is_a_document? self.class_name == “Document” end