Creating multiple child objects from the same form

Woei S. wrote:

Sorry to barge into your thread :slight_smile:

However one thing about this approach is that supposing one of your
answers fail validation, you will only get a rather cryptic error
message like “Answer is invalid”, with no other explanatory text or any
text fields highlighted (using the default scaffolds that is).

This will happen even if you did provide the appropriate error messages
in your Answers class! Is there any way to sort of “bubble” the error
messages from the child object up to the main form?

Thanks.

This solution isn’t as elegant as I at first thought. I’m trying to get
the edit method to work, and it seems like it’s repeating what I did for
the create method. And I thought ruby was all about DRY :slight_smile:

The model is pretty simple, but I don’t know how it will react when it
fails validation. There has to be a better way, right?

Woei S. wrote:

I hope there is a better way. :confused:

Surely there is someway to hack the _form partial into doing something
useful for objects that has_many instances of a child subclass… right?

crickets chirp

Hey RoR people, we’re talking to you! Haha.

Well, I think I’ll make the rest of this application and come back to
this later. Maybe I’ll have learned a bit more so it doesn’t feel quite
as hacked together. Thanks for the help everyone!

Xavier L. wrote:

Hey RoR people, we’re talking to you! Haha.

Well, I think I’ll make the rest of this application and come back to
this later. Maybe I’ll have learned a bit more so it doesn’t feel quite
as hacked together. Thanks for the help everyone!

A thought did pop into my head just now… maybe we can shift the
validation code into the controller, but it does seem like quite a waste
considering the child class has its own validation as well.

Just a suggestion though :slight_smile: