class Account < ActiveRecord::Base
validates_associated :site
end
Also, you should note that this validation will not fail if the association has not yet been
set (if it is nil or empty). If you wish to validate that the attribute is both present and valid, you
need to also use validates_presence_of.
In addition to the association attributes to validate, this method takes the configuration
options of :on and :if.
The :on option specifies for what methods this validation should be active. Valid options
are :save, :create, and :update. The default value is :save.
validates_associated :site, :on => :create
The :if option specifies a method, proc, or string that is called in order to determine
whether the validation should occur at all:
validates_associated :site, :if => :check_site
validates_associated :site, :if => "check_site"
validates_associated :site, :if => Proc.new {|a| a.create_step == 2 }
For more information regarding validations, see Chapter 4.
validates_confirmation_of(*attribute_names)
This method is used to validate that a virtual attribute matches the value of a real attribute,
such as dual e-mail or password entry boxes on a web form.
Pages:
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562