Forum: Ruby on Rails Best Idiom for form using multiple models

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Ccfe7d097475a32dc3ff78d6fc42c852?d=identicon&s=25 List Recv (lstrecv)
on 2006-01-16 00:47
What's the best idion when you need to present the user a single form,
whose data is loaded into several models?

Issues:
* How to display the errors together
* How do you handle one model being valid but not the other
* How do you do validations if one model's validity depends on the other

(I guess transactions could be used to handle #2 and #3...)
71f1b6b2c3fd9af2e8c52618fb91caa6?d=identicon&s=25 Jules (Guest)
on 2006-01-16 15:34
Transactions can be used, but you can also validate by hand.

For #1 I would write a helper just like error_messages_for(), but then
something that accepts an array of models and creates error messages
like:

The #{attribute} of #{themodel} should be at least 4 characters.

Jules
This topic is locked and can not be replied to.