Bart Braem wrote:> Say I have the following situation:
>
> class Client < ActiveRecord::Base
> has_many :orders
> ...
> end
>
> class Order < ActiveRecord::Base
> belongs_to :client
> ...
> end
>
> How can I validate that an order that is inputted at generation of a client
> is valid? I have a form where you can create new clients and input a
> comma-separated list of orders by name (named orders) .
> I''m trying to put something like this in the validate method of
the client
> model:
> errors.add("Invalid order") unless orders.each(valid?)
> How should I do that?
validates_associated :orders,
:on => :create,
:message => ''An order is invalid''
would work, but watch out for this bug:
http://dev.rubyonrails.org/ticket/4276
--
We develop, watch us RoR, in numbers too big to ignore.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk
-~----------~----~----~----~------~----~------~--~---