Validation Through Multiple Models from one Form

Hey All,

I have a form that submits data to multiple models.

I have

class Man < ActiveRecord::Base
has_many :notes
has_many :contacts

    validates_associated :contacts, :notes

validates_presence_of :first_name
validates_presence_of :last_name

class Contact < ActiveRecord::Base
belongs_to :man

    validates_presence_of :contact_info

class Note < ActiveRecord::Base
belongs_to :man

    validates_presence_of :notes

However when I submit the form blank, it will only validate for the Man
model. Not the other two. If I fill in the form then the data gets
submitted to the DB tables just fine, it just will not validate more
than that base model.

What am I missing??

Blessed Be

Phillip

On 6/21/07, Phillip B. [email protected] wrote:

has_many :contacts
class Note < ActiveRecord::Base
belongs_to :man

    validates_presence_of :notes

However when I submit the form blank, it will only validate for the Man
model. Not the other two. If I fill in the form then the data gets
submitted to the DB tables just fine, it just will not validate more
than that base model.

From: <
http://api.rubyonrails.org/classes/ActiveRecord/Validations/ClassMethods.html#M000948

"NOTE: This validation will not fail if the association hasn’EURO~t been
assigned. If you want to ensure that the association is both present and
guaranteed to be valid, you also need to use
validates_presence_ofhttp://api.rubyonrails.org/classes/ActiveRecord/Validations/ClassMethods.html#M000941
. "

What am I missing??

Blessed Be

Phillip


Posted via http://www.ruby-forum.com/.


Matt H [email protected]