Hi All,
I have my models as so:
class Asset < ActiveRecord::Base
validates_presence_of :title, :file, :class_name
set_inheritance_column ‘class_name’
end
class DocumentAsset < Asset
validates_presence_of :description
end
So a DocumentAsset has additional validations. But when I create and
save a new record (with params[:asset][:class_name] being
‘DocumentAsset’) in my controller:
def create
@asset = Asset.new()
@asset.attributes = @asset.attributes.merge(params[:asset])
if @asset.save
flash[:notice] = ‘Asset was created.’
redirect_to asset_list_url
else
render :action => ‘new’
end
end
It gets past the validations, even if the params[:asset][:description]
is nil.
Is this correct? If so, how can you specify custom validation for
subclasses of my Asset model.
Many Thanks,
Mark D.