Forum: Ruby on Rails Polymorphic Associations and Validation

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
on 2007-03-31 13:50
(Received via mailing list)

I want to validate values from a form. That wouldn't be very
difficult, but the model I want to polulate is in a polymorphic
Here are my models:

* Document (created_at, autor, resource_id, resource_type)
   ** Folder (name)
   ** Binary (name, data, content_type)

So a document can be either a folder or a binary. But here the problem
begins. Folder and Binary both have a "name"-column (this column is
not in the "documents"-table), so when users create a folder, they can
enter a name. When they upload a file, the "name"-column of the
"binaries"-table will be set automatically to the name of the file the
user has uploaded. That's no problem!
But I want to validate the name for a folder the user enteres. I have
two seperate forms for folder- and binary-creation, and I simply want
to validate the presence and the length of a new folder-name. But
where does the validation go? And how can I display the error-
I tried several things, but when I try to enter a folder without a
name there will be no new record in "folders" (which is good!) but no
error-message and an entry in the "documents"-table.
How can I validate those entries and how can I display error-messages?
And how can I prevent inserting "empty" entries to the "documents"-

Thanks for any help,
- Dominik
This topic is locked and can not be replied to.